1616package bootstrap
1717
1818import (
19+ "github.com/fatih/color"
1920 "github.com/spf13/cobra"
2021
2122 "github.com/ActiveMemory/ctx/internal/cli/add"
@@ -35,6 +36,7 @@ import (
3536 "github.com/ActiveMemory/ctx/internal/cli/sync"
3637 "github.com/ActiveMemory/ctx/internal/cli/task"
3738 "github.com/ActiveMemory/ctx/internal/cli/watch"
39+ "github.com/ActiveMemory/ctx/internal/config"
3840)
3941
4042// version is set at build time via ldflags
@@ -45,20 +47,59 @@ const version = "dev"
4547// The root command provides the entry point for all ctx subcommands and
4648// displays help information when invoked without arguments.
4749//
50+ // Global flags:
51+ // - --context-dir: Override the context directory path (default: .context)
52+ // - --quiet: Suppress non-essential output
53+ // - --no-color: Disable colored output
54+ //
4855// Returns:
4956// - *cobra.Command: The configured root command with usage and version info
5057func RootCmd () * cobra.Command {
51- return & cobra.Command {
58+ var contextDir string
59+ var noColor bool
60+
61+ cmd := & cobra.Command {
5262 Use : "ctx" ,
5363 Short : "Context - persistent context for AI coding assistants" ,
5464 Long : `Context (ctx) maintains persistent context files that help
5565 AI coding assistants understand your project's architecture, conventions,
5666 decisions, and current tasks.
57-
67+
5868 Use 'ctx init' to create a .context/ directory in your project,
5969 then use 'ctx status', 'ctx load', and 'ctx agent' to work with context.` ,
6070 Version : version ,
71+ PersistentPreRun : func (cmd * cobra.Command , args []string ) {
72+ // Apply global flag values
73+ if contextDir != "" {
74+ config .SetContextDir (contextDir )
75+ }
76+ if noColor {
77+ color .NoColor = true
78+ }
79+ },
6180 }
81+
82+ // Global flags available to all subcommands
83+ cmd .PersistentFlags ().StringVar (
84+ & contextDir ,
85+ "context-dir" ,
86+ "" ,
87+ "Override context directory path (default: .context)" ,
88+ )
89+ cmd .PersistentFlags ().BoolVar (
90+ & config .Quiet ,
91+ "quiet" ,
92+ false ,
93+ "Suppress non-essential output" ,
94+ )
95+ cmd .PersistentFlags ().BoolVar (
96+ & noColor ,
97+ "no-color" ,
98+ false ,
99+ "Disable colored output" ,
100+ )
101+
102+ return cmd
62103}
63104
64105// Initialize registers all ctx subcommands with the root command.
0 commit comments