Skip to content

refactor: Restructure project to internal/cmd/<resource>/ pattern#12

Merged
rianjs merged 11 commits intoopen-cli-collective:mainfrom
rianjs:feature/phase3-project-restructuring
Jan 11, 2026
Merged

refactor: Restructure project to internal/cmd/<resource>/ pattern#12
rianjs merged 11 commits intoopen-cli-collective:mainfrom
rianjs:feature/phase3-project-restructuring

Conversation

@rianjs
Copy link
Copy Markdown
Collaborator

@rianjs rianjs commented Jan 11, 2026

Summary

  • Restructure project to match CLI guide best practices with internal/cmd/<resource>/ pattern
  • Move main.go to cmd/slack-cli/main.go
  • Split monolithic command files into individual files per subcommand
  • Create shared output package to avoid import cycles
  • Update build configuration for new structure

Changes

New Structure

slack-cli/
├── cmd/slack-cli/
│   └── main.go
├── internal/
│   ├── cmd/
│   │   ├── root/
│   │   │   └── root.go
│   │   ├── channels/
│   │   │   ├── channels.go, list.go, get.go, create.go, etc.
│   │   ├── users/
│   │   │   ├── users.go, list.go, get.go
│   │   ├── messages/
│   │   │   ├── messages.go, send.go, update.go, etc.
│   │   ├── workspace/
│   │   │   ├── workspace.go, info.go
│   │   └── config/
│   │       ├── config.go, set_token.go, etc.
│   ├── client/
│   ├── keychain/
│   ├── output/
│   │   └── output.go (shared JSON flag)
│   └── version/

Build Configuration

  • Updated Makefile to build from ./cmd/slack-cli
  • Updated .goreleaser.yaml with main: ./cmd/slack-cli and ldflags for version injection
  • Updated .gitignore to allow cmd/slack-cli/ directory

Test plan

  • All existing unit tests pass
  • golangci-lint passes with no issues
  • Binary builds and runs correctly
  • --version shows correct info
  • All commands accessible via help

Fixes #3

🤖 Generated with Claude Code

rianjs and others added 11 commits January 11, 2026 09:38
Add CI workflow that runs on every push to main and every PR:
- Build and test job with race detection and coverage
- Lint job using golangci-lint

This establishes the foundation for validating all future changes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add .golangci.yml with standard linters:
- errcheck, govet, ineffassign, staticcheck, unused, misspell
- gofmt and goimports formatters with local prefix

Fix lint issues found:
- Replace fmt.Sscanf with strconv.ParseInt in formatTimestamp
- Properly handle resp.Body.Close() errors using named returns
- Fix import ordering with goimports

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add build-time version injection via ldflags:
- VERSION from git describe
- COMMIT from git rev-parse
- DATE from current time

Add new targets:
- test-cover: Run tests with coverage report
- test-short: Run quick tests
- lint: Run golangci-lint
- fmt: Run gofmt and goimports
- deps: Download and tidy dependencies
- verify: Verify go.mod

Update build target to output to bin/ directory.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add version package with variables set via ldflags:
- Version: semantic version from git tag
- Commit: git commit hash
- Date: build timestamp

Includes Info() helper for formatted version string.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add version information to root command:
- Set Version field from version package
- Custom version template showing commit and build date

Now `slack-cli --version` shows:
  slack-cli vX.Y.Z (commit: abc123, built: 2024-...)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Apply goimports formatting with local prefix to ensure consistent
import ordering across all command files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add NewWithConfig constructor for test injection with custom:
- Base URL (for httptest servers)
- Token
- HTTP client

Add 27 tests covering:
- Client configuration and initialization
- Channel operations (list, get, create, archive, unarchive, topic, purpose, invite)
- User operations (list, get)
- Message operations (send, update, delete, history, thread replies)
- Reactions (add, remove)
- Team info
- Pagination handling
- API error handling
- Network error handling
- Invalid JSON handling
- Auth header verification

All tests use httptest.NewServer for HTTP mocking.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add 12 tests covering:
- GetAPIToken from environment variable
- GetAPIToken when no token configured
- IsSecureStorage platform detection
- Config directory resolution (default and XDG_CONFIG_HOME)
- Config file operations (set, get, delete)
- Multiple keys handling
- Key updates
- File permissions (0600 for file, 0700 for directory)
- Values containing equals signs

Uses t.TempDir() and t.Setenv() for isolated testing.
Skip keychain-dependent tests on macOS where appropriate.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests for messages.go helper functions:
- formatTimestamp: timestamp parsing and formatting
- truncate: string truncation with newline handling
- buildDefaultBlocks: Block Kit structure generation

Add tests for command structure:
- Verify messages command registration
- Verify subcommands exist (send, update, delete, etc.)
- Verify command aliases (msg, m)

Uses table-driven tests with t.Run for clear test cases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive manual test documentation covering:
- Test environment setup and prerequisites
- Test data conventions
- Command tests for all operations:
  - Configuration (set-token, show, delete-token)
  - Channels (list, get, create, archive, topic, invite)
  - Users (list, get)
  - Messages (send, update, delete, history, thread, react)
  - Workspace (info)
- Edge cases and error scenarios
- Pre-release test execution checklist
- Troubleshooting guide

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This is a major restructuring to align with CLI guide best practices:

- Move main.go to cmd/slack-cli/main.go
- Create internal/cmd/root/root.go with root command
- Split each command file into internal/cmd/<resource>/ directory
  - channels: list, get, create, archive, unarchive, set_topic, set_purpose, invite
  - users: list, get
  - messages: send, update, delete, history, thread, react, unreact
  - workspace: info
  - config: set_token, delete_token, show
- Create internal/output package for shared output flag to avoid import cycles
- Update Makefile to build from new location
- Update .goreleaser.yaml with new main path and ldflags
- Update .gitignore to allow cmd/slack-cli/ directory

All tests pass and lint is clean.

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.

Epic: Phase 3 - Project Restructuring

1 participant