Skip to content

refactor: Restructure repository to follow cli-guide.md patterns#10

Merged
rianjs merged 1 commit intomainfrom
refactor/restructure-repository
Jan 13, 2026
Merged

refactor: Restructure repository to follow cli-guide.md patterns#10
rianjs merged 1 commit intomainfrom
refactor/restructure-repository

Conversation

@rianjs
Copy link
Copy Markdown
Collaborator

@rianjs rianjs commented Jan 13, 2026

Summary

  • Restructure from flat cmd/ layout to modular internal/cmd/<resource>/ pattern
  • Create public api/ package with types, errors, and domain-specific files
  • Create internal/view/ for output formatting (table/json/plain)
  • Create internal/version/ for build-time version injection
  • Rename internal/keychain/ to internal/config/
  • Replace --json flag with --output/-o (table|json|plain)
  • Add --no-color global flag
  • Add unit tests for view, version, and api packages

Test plan

  • make build succeeds
  • make test passes with race detection
  • All existing commands work identically
  • newrelic-cli --version shows version, commit, date
  • newrelic-cli apps list -o json outputs valid JSON
  • newrelic-cli apps list -o plain outputs tab-separated, no headers

Closes #1

🤖 Generated with Claude Code

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>
@rianjs rianjs merged commit 7803f7c into main Jan 13, 2026
1 check passed
@rianjs rianjs deleted the refactor/restructure-repository branch January 13, 2026 14:44
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>
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.

refactor: Restructure repository to follow cli-guide.md patterns

2 participants