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

Function runAliasAddCommand

cmd/root/alias.go:131–201  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, flags *aliasAddFlags)

Source from the content-addressed store, hash-verified

129}
130
131func runAliasAddCommand(cmd *cobra.Command, args []string, flags *aliasAddFlags) (commandErr error) {
132 telemetry.TrackCommand(cmd.Context(), "alias", append([]string{"add"}, args...))
133 defer func() { // do not inline this defer so that commandErr is not resolved early
134 telemetry.TrackCommandError(cmd.Context(), "alias", append([]string{"add"}, args...), commandErr)
135 }()
136
137 out := cli.NewPrinter(cmd.OutOrStdout())
138 name := args[0]
139 agentPath := args[1]
140
141 cfg, err := userconfig.Load()
142 if err != nil {
143 return fmt.Errorf("failed to load config: %w", err)
144 }
145
146 absAgentPath, err := pathx.ExpandHomeDir(agentPath)
147 if err != nil {
148 return err
149 }
150
151 // Convert relative paths to absolute for local files (not OCI references or URLs)
152 if !config.IsOCIReference(absAgentPath) && !config.IsURLReference(absAgentPath) && !filepath.IsAbs(absAgentPath) {
153 absAgentPath, err = filepath.Abs(absAgentPath)
154 if err != nil {
155 return fmt.Errorf("failed to resolve absolute path: %w", err)
156 }
157 }
158
159 // Create alias with options
160 alias := &userconfig.Alias{
161 Path: absAgentPath,
162 Yolo: flags.yolo,
163 Model: flags.model,
164 HideToolResults: flags.hideToolResults,
165 Sandbox: flags.sandbox,
166 }
167
168 // Store the alias
169 if err := cfg.SetAlias(name, alias); err != nil {
170 return err
171 }
172
173 // Save to file
174 if err := cfg.Save(); err != nil {
175 return fmt.Errorf("failed to save config: %w", err)
176 }
177
178 out.Printf("Alias '%s' created successfully\n", name)
179 out.Printf(" Alias: %s\n", name)
180 out.Printf(" Agent: %s\n", absAgentPath)
181 if flags.yolo {
182 out.Printf(" Yolo: enabled\n")
183 }
184 if flags.model != "" {
185 out.Printf(" Model: %s\n", flags.model)
186 }
187 if flags.hideToolResults {
188 out.Printf(" Hide tool results: enabled\n")

Callers 1

newAliasAddCmdFunction · 0.85

Calls 10

PrintfMethod · 0.95
TrackCommandFunction · 0.92
TrackCommandErrorFunction · 0.92
NewPrinterFunction · 0.92
LoadFunction · 0.92
IsOCIReferenceFunction · 0.92
IsURLReferenceFunction · 0.92
ContextMethod · 0.80
SetAliasMethod · 0.80
SaveMethod · 0.80

Tested by

no test coverage detected