Skip to content

The Framework CLI

While GTB provides a powerful library for building CLI applications, it also includes its own internal CLI (the gtb binary). This tool is the "orchestrator" for your development workflow, designed to solve the problems of boilerplate, inconsistency, and architectural drift.

Why a Framework CLI?

Building a high-quality CLI involves a lot of repetitive work: setting up Cobra commands, configuring dependency injection (Props), managing assets, and writing documentation. The Framework CLI exists to:

  • Enforce Best Practices: Every project generated by the CLI follows the same proven architectural patterns.
  • Eliminate Boilerplate: Generate complex command hierarchies with a single command.
  • Maintain Sync: Uses a manifest.yaml as the source of truth, allowing you to "regenerate" your code as your design evolves.

Core Workflows

1. Project Scaffolding (generate project)

The CLI can bootstrap an entire repository with a single command. It sets up the main entry point, root command, logging, configuration management, and asset embedding automatically.

2. Command Generation (generate command)

Instead of manually creating Go files and registering them in Cobra, you use the CLI to add new subcommands.

  • Interactive Prompts: Capture command name, summary, and flags through a user-friendly TUI (powered by Huh).
  • Automatic Registration: The CLI updates the parent command's registration logic and creates the necessary implementation files in pkg/cmd.
  • Instant Documentation: Generating a command also populates the docs/ folder with AI-enhanced content, ensuring your tool remains self-documenting as it grows.

3. Manifest-Driven Development (regenerate)

GTB uses a Manifest File (.gtb/manifest.yaml) to track the structure of your application.

  • Design First: You can modify the manifest to rename commands or change hierarchies.
  • Sync: Running regenerate synchronizes your Go source code with the manifest, ensuring that your implementation always matches your intended design.

4. Intelligent Documentation (generate docs)

As explored in the Integrated Documentation section, the CLI uses AI to analyze your source code and produce high-quality Markdown documentation that is ready for the built-in browser.

The Problems It Solves

  • The "Copy-Paste" Problem: Developers often copy-paste command implementations, leading to inconsistent flag names or error handling. The CLI ensures every command starts from a clean, standard template.
  • Stale Documentation: By automating doc generation, the CLI ensures that your documentation never falls behind your code.
  • Naming Inconsistency: The CLI helps enforce naming conventions across large CLI tools, making the final product feel polished and professional.

Summary

The Framework CLI is not just a code generator; it is the Guardian of Architecture for your project. By using it, you ensure that your tool remains maintainable, consistent, and fully integrated with the deep features offered by the GTB framework.