Skip to content

Commands Overview

GTB provides a set of essential built-in commands that are automatically included in every CLI tool. These commands provide core functionality for configuration management, version checking, self-updating, interactive documentation, and AI agent integration.

Available Commands

Command Purpose
Root Application entry point and service orchestration.
Init Tool configuration and environment setup.
Config Programmatic config access for CI and scripted setup. (opt-in)
Version Version display and update checking.
Update Automated binary updates and migration.
Docs Interactive TUI documentation browser.
Doctor Environment and configuration health checks.
MCP AI agent integration (Model Context Protocol).

Command Integration

Automatic Registration

All built-in commands are automatically registered when you create a root command:

package main

import (
    "embed"
    "gitlab.com/phpboyscout/go-tool-base/pkg/cmd/root"
    "gitlab.com/phpboyscout/go-tool-base/pkg/props"
)

//go:embed assets/*
var assets embed.FS

func main() {
    props := &props.Props{
        Tool: props.Tool{
            Name: "mytool",
            // ... other configuration
        },
        // ... other props
    }

    // Initialize props...
    props.Assets = props.NewAssets(&assets)

    // Create root command. Built-in commands (init, version, update, docs, mcp)
    // are automatically registered unless explicitly disabled.
    rootCmd := root.NewCmdRoot(props)
    rootCmd.Execute()
}

Disabling Commands

You can disable specific built-in commands by configuring the Features field in props.Tool:

props := &props.Props{
    Tool: props.Tool{
        Name: "mytool",
        Features: props.SetFeatures(
            props.Disable(props.UpdateCmd), // Disable the update command
            props.Disable(props.InitCmd),   // Disable the init command
            props.Disable(props.McpCmd),    // Disable the MCP command
        ),
    },
}

Available disable options:

  • props.UpdateCmd: Disables the update command.
  • props.InitCmd: Disables the init command.
  • props.McpCmd: Disables the mcp command.
  • props.DocsCmd: Disables the docs command.
  • props.DoctorCmd: Disables the doctor command.
  • props.ConfigCmd: Disables the config command (note: already disabled by default).

Note: The version command cannot be disabled as it's essential for troubleshooting.

Enabling Optional Commands

Some commands are opt-in and disabled by default. Enable them via props.SetFeatures:

props := &props.Props{
    Tool: props.Tool{
        Features: props.SetFeatures(
            props.Enable(props.AiCmd),    // Enable AI provider configuration in 'init'
            props.Enable(props.ConfigCmd), // Enable programmatic config access
        ),
    },
}

Available opt-in commands:

  • props.AiCmd: Enables AI provider configuration during init.
  • props.ConfigCmd: Enables the config get/set/list/validate command group.

Custom Commands

You can easily add your own custom commands alongside the built-in ones by passing them to NewCmdRoot:

customCmd := newCustomCommand(props)
rootCmd := root.NewCmdRoot(props, customCmd)

See the Development Guide for more details on implementing custom commands.