MCPcopy
hub / github.com/docker/docker-agent / NewRootCmd

Function NewRootCmd

cmd/root/root.go:39–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37}
38
39func NewRootCmd() *cobra.Command {
40 var flags rootFlags
41
42 cmd := &cobra.Command{
43 Use: "docker-agent",
44 Short: "Docker AI Agent Runner",
45 Long: `Docker AI Agent Runner.
46
47New to docker agent? Take the hands-on tour: docker agent getting-started`,
48 Example: ` docker-agent run
49 docker-agent run ./agent.yaml
50 docker-agent run agentcatalog/pirate`,
51 PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
52 // Apply directory overrides before anything else so that
53 // logging, telemetry, and config loading honour them.
54 if dir := flags.cacheDir; dir != "" {
55 paths.SetCacheDir(dir)
56 }
57 if dir := flags.configDir; dir != "" {
58 paths.SetConfigDir(dir)
59 }
60 if dir := flags.dataDir; dir != "" {
61 paths.SetDataDir(dir)
62 }
63
64 // Set the version for automatic telemetry initialization
65 telemetry.SetGlobalTelemetryVersion(version.Version)
66
67 // Print startup message only on first installation/setup
68 if isFirstRun() && os.Getenv("CAGENT_HIDE_TELEMETRY_BANNER") != "1" && os.Getenv("DOCKER_AGENT_HIDE_TELEMETRY_BANNER") != "1" {
69 welcomeMsg := fmt.Sprintf(`
70Welcome to docker agent! 🚀
71
72For any feedback, please visit: %s
73`, feedback.Link)
74 fmt.Fprint(cmd.ErrOrStderr(), welcomeMsg)
75
76 // Only show telemetry notice when telemetry is enabled
77 if telemetry.GetTelemetryEnabled() {
78 telemetryMsg := `
79We collect anonymous usage data to help improve docker agent. To disable:
80 - Set environment variable: TELEMETRY_ENABLED=false
81`
82 fmt.Fprint(cmd.ErrOrStderr(), telemetryMsg)
83 }
84
85 fmt.Fprintln(cmd.ErrOrStderr())
86 }
87
88 // Initialize logging before anything else so logs don't break TUI
89 if err := flags.setupLogging(); err != nil {
90 // If logging setup fails, fall back to stderr so we still get logs
91 slog.SetDefault(slog.New(slog.NewTextHandler(cmd.ErrOrStderr(), &slog.HandlerOptions{
92 Level: func() slog.Level {
93 if flags.debugMode {
94 return slog.LevelDebug
95 }
96 return slog.LevelInfo

Callers 4

TestSandboxAllowDenyListFunction · 0.85
ExecuteFunction · 0.85

Calls 15

setupLoggingMethod · 0.95
SetCacheDirFunction · 0.92
SetConfigDirFunction · 0.92
SetDataDirFunction · 0.92
GetTelemetryEnabledFunction · 0.92
isFirstRunFunction · 0.85
initOTelSDKFunction · 0.85
newVersionCmdFunction · 0.85
newRunCmdFunction · 0.85
newNewCmdFunction · 0.85