refactor: Restructure repository to follow cli-guide.md patterns#10
Merged
refactor: Restructure repository to follow cli-guide.md patterns#10
Conversation
This restructures the codebase from a flat cmd/ layout to a modular, testable architecture with proper separation of concerns. Changes: - Create public api/ package with types, errors, and domain-specific files - Create internal/cmd/ with Options pattern for all commands - Create internal/view/ for output formatting (table/json/plain) - Create internal/version/ for build-time version injection - Rename internal/keychain/ to internal/config/ - Move entry point to cmd/newrelic-cli/main.go - Replace --json flag with --output/-o (table|json|plain) - Add --no-color global flag - Update Makefile with new targets and ldflags - Add unit tests for view, version, and api packages The new structure enables: - Testable commands via Options struct and injectable clients - Public API package that can be imported by other Go projects - Consistent output formatting across all commands - Better separation between CLI, business logic, and API Closes #1 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
piekstra
approved these changes
Jan 13, 2026
This was referenced Jan 13, 2026
rianjs
added a commit
that referenced
this pull request
Jan 13, 2026
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
added a commit
that referenced
this pull request
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: ```bash 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](https://claude.ai/code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cmd/layout to modularinternal/cmd/<resource>/patternapi/package with types, errors, and domain-specific filesinternal/view/for output formatting (table/json/plain)internal/version/for build-time version injectioninternal/keychain/tointernal/config/--jsonflag with--output/-o(table|json|plain)--no-colorglobal flagTest plan
make buildsucceedsmake testpasses with race detectionnewrelic-cli --versionshows version, commit, datenewrelic-cli apps list -o jsonoutputs valid JSONnewrelic-cli apps list -o plainoutputs tab-separated, no headersCloses #1
🤖 Generated with Claude Code