bau/command

Search:
Group by:

Implements Bau's command-line parser and command handlers.

Types

CliOptions = object
  command*: Command          ## Selected command.
  profile*: string           ## Build profile.
  profileExplicit*: bool     ## True when `--profile` was provided.
  jobs*: int                 ## Parallel build job count.
  jobsExplicit*: bool        ## True when `--jobs` was provided.
  verbose*: bool             ## Whether verbose output is enabled.
  quiet*: bool               ## Whether normal progress output is suppressed.
  help*: bool                ## Whether command-specific help was requested.
  watch*: bool               ## Whether to watch files and rerun work.
  color*: string             ## Color mode: `auto`, `always`, or `never`.
  args*: seq[string]         ## Positional command arguments.
  taskName*: string          ## Task or plugin name.
  force*: bool               ## Force overwrites or bypass cached state.
  timings*: bool             ## Print command timing information.
  open*: bool                ## Open generated docs when supported.
  dryRun*: bool              ## Plan without writing when supported.
  keepGoing*: bool           ## Continue independent task deps after failures.
  allTargets*: bool          ## Select all eligible targets.
  changed*: bool             ## Limit work to changed tests where supported.
  json*: bool                ## Request JSON output.
  list*: bool                ## Request list output for commands that support it.
  rawCommand*: string        ## Original first CLI token before alias resolution.
  rawArgs*: seq[string]      ## Original command-line arguments.
  aliasResolved*: bool       ## True when this parse came from an alias expansion.
  offline*: bool             ## Avoid network dependency operations.
  locked*: bool              ## Require an up-to-date lockfile.
  update*: bool              ## Request update mode for install/deps commands.
  remove*: bool              ## Request removal mode for install commands.
  write*: bool               ## Write discovered changes.
  format*: string            ## Output format such as `text`, `json`, or `dot`.
  formatVersion*: int        ## Stable JSON format version.
  features*: seq[string]     ## Requested feature names.
  allFeatures*: bool         ## Enable every feature.
  noDefaultFeatures*: bool   ## Disable the default feature.
  since*: string             ## Git revision or ref for affected analysis.
  precise*: string           ## Exact dependency revision for updates.
  docOutDir*: string         ## Documentation output directory override.
  docEntrypoints*: seq[string] ## Extra documentation entrypoint files.
  docSkipExamples*: bool     ## Skip runnable examples during docs.
  docIncludePrivate*: bool   ## Include private symbols in docs.
  docNoIndex*: bool          ## Suppress docs index generation.
  testShowOutput*: string    ## Test output mode override.
  testNoMatrix*: bool        ## Run a single test profile instead of the matrix.
  testFull*: bool            ## Run the full configured test matrix.
  testFast*: bool            ## Run the fast local test mode.
  testNoRunner*: bool        ## Discover test files instead of using a runner.
  installDir*: string        ## Installation directory override.
  passthroughArgs*: seq[string] ## Arguments passed after `--`.
  initInfo*: ProjectInitInfo ## Project initialization metadata.
  agentTargets*: seq[string] ## Agent hosts selected for MCP setup.
Parsed command-line options.
Command = enum
  cmdNone,                  ## No command was selected.
  cmdBuild,                 ## Build project targets.
  cmdRun,                   ## Build and run a target.
  cmdTest,                  ## Run tests.
  cmdCheck,                 ## Type-check configured targets.
  cmdDoc,                   ## Generate API documentation.
  cmdInstall,               ## Install a built binary.
  cmdUpdate,                ## Update an installed binary.
  cmdUninstall,             ## Remove an installed binary.
  cmdClean,                 ## Remove Bau Outputs.
  cmdDeps,                  ## Manage dependencies.
  cmdAdd,                   ## Add a dependency.
  cmdRemove,                ## Remove a dependency.
  cmdInit,                  ## Initialize the current directory.
  cmdNew,                   ## Create a new project directory.
  cmdConvert,               ## Convert a Nimble project.
  cmdVersion,               ## Print version information.
  cmdHelp,                  ## Print help text.
  cmdTask,                  ## Run a custom task.
  cmdFmt,                   ## Format source files.
  cmdLint,                  ## Run style checks.
  cmdCi,                    ## Run the local CI sequence.
  cmdOutdated,              ## Report dependency status.
  cmdTree,                  ## Print dependency tree output.
  cmdExplain,               ## Explain target freshness state.
  cmdPublish,               ## Submit a package publication.
  cmdBump,                  ## Increment the project package version.
  cmdMcp,                   ## Configure or run the MCP server.
  cmdShell,                 ## Open a shell with Bau environment.
  cmdShellInit,             ## Add Bau's binary directory to the selected shell.
  cmdPlugin,                ## Delegate to an external `bau-*` command.
  cmdCompileCommands,       ## Generate compile command databases.
  cmdCiTemplate,            ## Generate CI templates.
  cmdMetadata,              ## Print project metadata.
  cmdGraph,                 ## Print project graph output.
  cmdQuery,                 ## Query dependencies.
  cmdTailor,                ## Discover target declarations.
  cmdPackage,               ## Inspect package contents.
  cmdEnv,                   ## Print Bau environment details.
  cmdAffected,              ## Run affected-work analysis.
  cmdCache,                 ## Inspect or clean task cache.
  cmdDoctor                  ## Check toolchain health.
Parsed CLI command.

Procs

proc affectedCommand(opts: CliOptions) {.
    ...raises: [ValueError, OSError, IOError, TomlError, KeyError, Exception], tags: [
    ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect,
    WriteDirEffect, ExecIOEffect, TimeEffect, WriteEnvEffect], forbids: [].}
Execute affected-work commands.
proc applyDependencyArgs(opOpts: var OperationOptions; args: openArray[string]) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Parse dependency-specific CLI flags into operation options.
proc bumpCommand(opts: CliOptions) {....raises: [IOError, ValueError, OSError,
    Exception, IOError], tags: [WriteIOEffect, ReadDirEffect, ReadIOEffect,
                                RootEffect, WriteDirEffect], forbids: [].}
Increment the project package version in Bau metadata.
proc cacheCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception, LibraryError, SslError], tags: [
    ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect,
    WriteDirEffect, TimeEffect], forbids: [].}
Execute task-cache inspection and cleanup commands.
proc ciCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception], tags: [ReadDirEffect, ReadIOEffect,
    RootEffect, WriteIOEffect, ReadEnvEffect, ExecIOEffect, TimeEffect,
    WriteDirEffect], forbids: [].}
Execute Bau's local CI sequence.
proc convertCommand(opts: CliOptions) {....raises: [OSError, ValueError, IOError,
    KeyError], tags: [ReadDirEffect, ReadIOEffect, WriteDirEffect, WriteIOEffect],
                                        forbids: [].}
Execute Nimble-to-Bau conversion.
proc defaultOptions(): CliOptions {....raises: [], tags: [], forbids: [].}
Return default CLI options before parsing user arguments.
proc depsCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception], tags: [ReadDirEffect, ReadIOEffect,
    RootEffect, WriteIOEffect, ReadEnvEffect, ExecIOEffect, TimeEffect,
    WriteDirEffect], forbids: [].}
Execute dependency subcommands such as sync, update, lock, and verify.
proc dispatchCommand(opts: CliOptions) {....raises: [ValueError, OSError,
    Exception, TomlError, KeyError, IOError, OSError, ValueError, OSError,
    Exception, TomlError, KeyError, OSError, IOError, OSError, CatchableError,
    JsonParsingError, OSError, LibraryError, SslError], tags: [ReadDirEffect,
    ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, WriteEnvEffect,
    TimeEffect, WriteDirEffect, ExecIOEffect], forbids: [].}
Dispatch parsed CLI options to the selected command implementation.
proc doctorCommand(opts: CliOptions) {....raises: [OSError, Exception, KeyError,
    IOError], tags: [ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect,
                     ReadEnvEffect, ExecIOEffect, TimeEffect], forbids: [].}
Execute toolchain and project health checks.
proc envCommand(opts: CliOptions) {....raises: [OSError, Exception, ValueError,
    KeyError, IOError], tags: [ReadDirEffect, ReadIOEffect, RootEffect,
                               WriteIOEffect, ReadEnvEffect], forbids: [].}
Execute the environment-reporting command.
proc explainCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception, JsonParsingError], tags: [ReadDirEffect,
    ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect], forbids: [].}
Execute build-cache explanation output.
proc fmtCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError], tags: [
    ReadDirEffect, ReadEnvEffect, ReadIOEffect, WriteIOEffect, ExecIOEffect,
    RootEffect, TimeEffect], forbids: [].}
Execute the fmt command.
proc fmtSources(projectDir: string; verbose: bool = false) {.
    ...raises: [OSError, IOError, ValueError], tags: [ReadDirEffect, ReadEnvEffect,
    ReadIOEffect, WriteIOEffect, ExecIOEffect, RootEffect, TimeEffect],
    forbids: [].}
Format Nim files under a project's src directory with nimpretty.
proc generateCompileCommands(projectDir: string; profile: string;
    featureSelection: FeatureSelection = FeatureSelection()) {.
    ...raises: [IOError, ValueError, OSError, TomlError, KeyError, Exception], tags: [
    ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect,
    WriteDirEffect], forbids: [].}
Generate compile_commands.json for one project.
proc graphCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception], tags: [ReadDirEffect, ReadIOEffect,
    RootEffect, WriteIOEffect, ReadEnvEffect], forbids: [].}
Execute the graph command.
proc installCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    IOError, TomlError, KeyError, Exception], tags: [ReadDirEffect,
    WriteIOEffect, ReadIOEffect, RootEffect, ReadEnvEffect, WriteDirEffect,
    WriteEnvEffect, ExecIOEffect, TimeEffect], forbids: [].}
Execute install, update, and uninstall commands.
proc lintCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception], tags: [ReadDirEffect, ReadIOEffect,
    RootEffect, WriteIOEffect, ReadEnvEffect, ExecIOEffect, TimeEffect],
                                     forbids: [].}
Execute the lint command.
proc mcpCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    KeyError], tags: [ReadDirEffect, ReadIOEffect, WriteDirEffect,
                      WriteIOEffect, RootEffect], forbids: [].}
Execute MCP helper commands.
proc metadataCommand(opts: CliOptions) {.
    ...raises: [ValueError, OSError, IOError, TomlError, KeyError, Exception], tags: [
    ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect],
    forbids: [].}
Execute the metadata command.
proc outdatedCommand(opts: CliOptions) {.
    ...raises: [ValueError, OSError, IOError, TomlError, KeyError, Exception], tags: [
    ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect,
    ExecIOEffect, TimeEffect], forbids: [].}
Execute dependency status reporting.
proc packageCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    Exception, KeyError], tags: [ReadDirEffect, ReadIOEffect, RootEffect,
                                 WriteIOEffect, ReadEnvEffect, WriteDirEffect],
                                        forbids: [].}
Execute package inspection and manifest generation.
proc parseCliOptions(params: seq[string] = commandLineParams()): CliOptions {.
    ...raises: [OSError, ValueError],
    tags: [ReadDirEffect, ReadEnvEffect, ReadIOEffect], forbids: [].}
Parse command-line parameters into CliOptions.
proc pluginCommand(opts: CliOptions) {....raises: [OSError, IOError, ValueError], tags: [
    ReadDirEffect, ReadEnvEffect, ReadIOEffect, WriteIOEffect, ExecIOEffect,
    RootEffect, TimeEffect], forbids: [].}
Execute an external bau-* command.
proc printHelp() {....raises: [], tags: [], forbids: [].}
Print Bau's command-line help text.
proc printMcpCommandHelp() {....raises: [], tags: [], forbids: [].}
Print help for the mcp command family.
proc printTaskCommandHelp() {....raises: [], tags: [], forbids: [].}
Print help for the task command.
proc printTaskDetails(cfg: BauConfig; projectDir: string; opts: CliOptions) {.
    ...raises: [IOError, KeyError, OSError, ValueError], tags: [WriteIOEffect,
    ReadEnvEffect, ReadDirEffect, RootEffect, ReadIOEffect], forbids: [].}
Print metadata for one configured task.
proc printTaskList(cfg: BauConfig) {....raises: [], tags: [], forbids: [].}
Print configured tasks with descriptions and useful flags.
proc printVersion() {....raises: [], tags: [], forbids: [].}
Print Bau's version string.
proc publishCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    Exception, KeyError], tags: [ReadDirEffect, ReadIOEffect, RootEffect,
                                 WriteIOEffect, ReadEnvEffect, WriteDirEffect,
                                 ExecIOEffect, TimeEffect], forbids: [].}
Execute package publishing or publish dry-run inspection.
proc queryCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception], tags: [ReadDirEffect, WriteIOEffect,
    ReadIOEffect, RootEffect, ReadEnvEffect], forbids: [].}
Execute dependency query commands.
proc shellCommand(opts: CliOptions) {....raises: [OSError, ValueError, KeyError,
    IOError], tags: [ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect,
                     ReadEnvEffect, WriteEnvEffect, ExecIOEffect, TimeEffect],
                                      forbids: [].}
Execute an interactive shell with Bau environment variables set.
proc shellInitCommand(opts: CliOptions) {....raises: [IOError, OSError, KeyError], tags: [
    WriteIOEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteDirEffect],
    forbids: [].}
Add Bau's binary directory to the selected shell startup file.
proc tailorCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception], tags: [ReadDirEffect, ReadIOEffect,
    RootEffect, WriteIOEffect, ReadEnvEffect, WriteDirEffect], forbids: [].}
Execute target-discovery and config-tailoring commands.
proc treeCommand(opts: CliOptions) {....raises: [ValueError, OSError, IOError,
    TomlError, KeyError, Exception], tags: [ReadDirEffect, ReadIOEffect,
    RootEffect, WriteIOEffect, ReadEnvEffect], forbids: [].}
Execute dependency tree reporting.
proc watchLoop(opts: CliOptions) {....raises: [OSError, IOError, Exception,
    KeyError], tags: [ReadDirEffect, WriteIOEffect, TimeEffect, ReadIOEffect,
                      RootEffect, ReadEnvEffect, WriteEnvEffect, WriteDirEffect,
                      ExecIOEffect], forbids: [].}
Watch project files and rerun the selected build-like command.