Skip to content

feat: Add shell scripting composability#14

Merged
rianjs merged 1 commit intomainfrom
feat/shell-composability
Jan 13, 2026
Merged

feat: Add shell scripting composability#14
rianjs merged 1 commit intomainfrom
feat/shell-composability

Conversation

@rianjs
Copy link
Copy Markdown
Collaborator

@rianjs rianjs commented Jan 13, 2026

Summary

Add standardized exit codes for shell scripting composability.

Exit Codes

Code Meaning
0 Success
1 General error
2 Usage error
3 Config error (missing API key/account ID)
4 Auth error (401/403)
5 API error (4xx)
6 Server error (5xx)

Usage

Shell scripts can now check exit codes for programmatic error handling:

newrelic-cli apps list || handle_error $?

# Or more specifically:
newrelic-cli apps list
case $? in
  0) echo "Success" ;;
  3) echo "Please configure API key" ;;
  4) echo "Authentication failed" ;;
  *) echo "Command failed" ;;
esac

Changes

  • Add internal/exitcode/ package with exit code constants
  • Add exitcode.FromHTTPStatus() to map HTTP status codes to exit codes
  • Update main.go to use typed exit codes based on error type

Deferred to Follow-up PR

The following features from the original PR were deferred due to codebase restructuring in PR #10:

  • --limit/-l flag on list commands
  • --force/-f flag on delete commands

Closes #5


🤖 Generated with Claude Code

@rianjs rianjs requested a review from piekstra January 13, 2026 13:02
Copy link
Copy Markdown
Collaborator

@piekstra piekstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

examples in the pr description show newrelic which is either an alias, or claude got confused and downloaded the "official" cli

@rianjs
Copy link
Copy Markdown
Collaborator Author

rianjs commented Jan 13, 2026

Rebase Plan

PR #10 restructured the entire codebase, so this PR needs a careful rebase. Here's the plan:

What We're Keeping

  • internal/exitcode/ - Exit code constants (0-6) for shell scripting
  • Exit code handling in main.go

What We're Deferring (Follow-up PR)

  • --limit flag on list commands
  • --force flag on delete commands

Why?

The original PR modified cmd/*.go files which have been moved to internal/cmd/{subcommand}/ in main. The internal/client/client.go moved to api/. The renderer package duplicates the new internal/view/ package.

Rather than port all features to the new structure in this rebase, we'll:

  1. Complete a minimal rebase keeping the exit code functionality
  2. Create a follow-up issue for the remaining flags

Exit Codes Added

Code Meaning
0 Success
1 General error
2 Usage error
3 Config error (missing API key/account ID)
4 Auth error (401/403)
5 API error (4xx)
6 Server error (5xx)

Add standardized exit codes (0-6) to enable programmatic error handling:
- 0: Success
- 1: General error
- 2: Usage error
- 3: Config error (missing API key/account ID)
- 4: Auth error (401/403)
- 5: API error (4xx)
- 6: Server error (5xx)

Shell scripts can now check exit codes:
  newrelic-cli apps list || handle_error $?

Note: --limit and --force flags deferred to follow-up PR due to
codebase restructuring in PR #10.

Closes #5

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rianjs rianjs force-pushed the feat/shell-composability branch from cbbab30 to 11e6ffd Compare January 13, 2026 15:16
@rianjs rianjs merged commit 511d129 into main Jan 13, 2026
2 checks passed
@rianjs rianjs deleted the feat/shell-composability branch January 13, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Improve composability for shell scripting

2 participants