Skip to content

feat: Improve composability for shell scripting #5

@rianjs

Description

@rianjs

Description

Make the CLI fully composable with other *nix tools by adding plain output format, standardizing flags, implementing meaningful exit codes, and separating stdout/stderr.

Tasks

5.1 Add --output plain format

  • Add plain format to view.Renderer
  • Use tabs as delimiters for easy parsing with cut
  • No headers in plain mode
  • No color codes in plain mode
  • Update all list commands to support plain output
  • Examples that should work:
    • newrelic-cli apps list -o plain | cut -f1 (Just IDs)
    • newrelic-cli apps list -o plain | grep "production" (Filter)
    • newrelic-cli apps list -o json | jq -r '.[].id' (JSON processing)

5.2 Standardize flag behavior across all commands

  • Global flags: --output/-o, --no-color, --verbose/-v
  • Add --force/-f to destructive commands
  • Add --limit/-l to all list commands

5.3 Implement meaningful exit codes

  • Create internal/exitcode/exitcode.go:
    • Success = 0
    • GeneralError = 1
    • UsageError = 2
    • ConfigError = 3
    • AuthError = 4
    • APIError = 5
    • ServerError = 6
  • Update root command error handling
  • Document exit codes in README

5.4 Separate stdout and stderr

  • Data output (tables, JSON, plain) → stdout only
  • Status messages, progress, warnings → stderr only
  • Update Renderer to accept separate writers

Integration Tests

Command Expected
apps list -o plain | wc -l Count of apps
apps list -o plain | cut -f1 Just IDs
apps list --limit 5 Exactly 5 results
Invalid args → echo $? Exit code 2

Acceptance Criteria

  • Plain output works with grep, cut, awk, xargs
  • All flags documented in README
  • Exit codes documented and consistent
  • Piping works without status message pollution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions