Skip to content

Restructure Packages #352

@thde

Description

@thde

Based on the Go package name guidelines (Go Blog and Effective Go), I propose the following for restructuring the nctl codebase:

Move everything to internal/

Since nctl is a CLI tool and not intended to be used as a public library, moving the core logic into internal/ ensures encapsulation and prevents accidental external dependencies.

Consolidate UI and Formatting

The current internal/cli, internal/format, and internal/logbox packages all deal with how information is presented to the user. These should be merged into a single package named internal/render (or internal/ui).

Refactor util and validation

Go guidance strongly suggests avoiding generic util packages. Instead, functionality should be organized by domain.

Eliminate api/util: Move domain-specific helpers directly into internal/api/ using domain-named files.
* api/util/apps.go -> internal/api/apps.go
* api/util/bucket.go -> internal/api/bucket.go
* api/util/release.go -> internal/api/release.go

Move api/validation to internal/api/validation. If the validation logic is small, it could also be merged directly into internal/api.

Improve Test Helpers

Rename internal/test to internal/testutil. This follows the common Go pattern for packages that provide shared testing utilities (mocks, client builders, etc.) rather than the tests themselves.

Proposed Structure Overview

    1 nctl/
    2 ├── main.go
    3 ├── internal/
    4 │   ├── cmd/           # All CLI command implementations
    5 │   │   ├── get/
    6 │   │   ├── create/
    7 │   │   └── ...
    8 │   ├── api/           # Internal API client and domain helpers
    9 │   │   ├── config/
   10 │   │   ├── validation/
   11 │   │   ├── apps.go    # (former api/util/apps.go)
   12 │   │   └── client.go
   13 │   ├── render/        # UI, Formatting, and Error presentation
   14 │   │   ├── error.go
   15 │   │   ├── print.go
   16 │   │   └── logbox.go
   17 │   └── testutil/      # Shared testing utilities
   18 └── completions/       # Shell completion scripts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions