MCPcopy Index your code
hub / github.com/coder/coder / Command

Method Command

cli/root.go:244–559  ·  view source on GitHub ↗
(subcommands []*serpent.Command)

Source from the content-addressed store, hash-verified

242}
243
244func (r *RootCmd) Command(subcommands []*serpent.Command) (*serpent.Command, error) {
245 if r.clock == nil {
246 r.clock = quartz.NewReal()
247 }
248
249 fmtLong := `Coder %s — A tool for provisioning self-hosted development environments with Terraform.
250`
251 hiddenAgentAuth := &AgentAuth{}
252 cmd := &serpent.Command{
253 Use: "coder [global-flags] <subcommand>",
254 Long: fmt.Sprintf(fmtLong, buildinfo.Version()) + FormatExamples(
255 Example{
256 Description: "Start a Coder server",
257 Command: "coder server",
258 },
259 Example{
260 Description: "Get started by creating a template from an example",
261 Command: "coder templates init",
262 },
263 ),
264 Handler: func(i *serpent.Invocation) error {
265 if r.versionFlag {
266 return r.version(defaultVersionInfo).Handler(i)
267 }
268 // The GIT_ASKPASS environment variable must point at
269 // a binary with no arguments. To prevent writing
270 // cross-platform scripts to invoke the Coder binary
271 // with a `gitaskpass` subcommand, we override the entrypoint
272 // to check if the command was invoked.
273 if gitauth.CheckCommand(i.Args, i.Environ.ToOS()) {
274 return gitAskpass(hiddenAgentAuth).Handler(i)
275 }
276 return i.Command.HelpHandler(i)
277 },
278 }
279
280 cmd.AddSubcommands(subcommands...)
281
282 // Set default help handler for all commands.
283 cmd.Walk(func(c *serpent.Command) {
284 if c.HelpHandler == nil {
285 c.HelpHandler = helpFn()
286 }
287 })
288
289 var merr error
290 // Add [flags] to usage when appropriate.
291 cmd.Walk(func(cmd *serpent.Command) {
292 const flags = "[flags]"
293 if strings.Contains(cmd.Use, flags) {
294 merr = errors.Join(
295 merr,
296 xerrors.Errorf(
297 "command %q shouldn't have %q in usage since it's automatically populated",
298 cmd.FullUsage(),
299 flags,
300 ),
301 )

Callers 15

setupKeyringTestEnvFunction · 0.95
TestUseKeyringFunction · 0.95
RunWithSubcommandsMethod · 0.95
TestCommandHelpFunction · 0.95
TestHandlersOKFunction · 0.95
createAgentWithFlagsFunction · 0.95
getRootFunction · 0.95
NewFunction · 0.95

Calls 15

versionMethod · 0.95
AttachOptionsMethod · 0.95
VersionFunction · 0.92
CheckCommandFunction · 0.92
DefaultDirFunction · 0.92
FormatExamplesFunction · 0.85
gitAskpassFunction · 0.85
helpFnFunction · 0.85
PrintDeprecatedOptionsFunction · 0.85
NameMethod · 0.65
FlushMethod · 0.65
HandlerMethod · 0.45

Tested by 15

setupKeyringTestEnvFunction · 0.76
TestUseKeyringFunction · 0.76
TestCommandHelpFunction · 0.76
TestHandlersOKFunction · 0.76
createAgentWithFlagsFunction · 0.76
getRootFunction · 0.76
TestServer_SingleFunction · 0.76