MCPcopy
hub / github.com/digitalocean/doctl / cmdBuilderWithInit

Function cmdBuilderWithInit

commands/command.go:74–118  ·  view source on GitHub ↗
(parent *Command, cr CmdRunner, cliText, shortdesc string, longdesc string, out io.Writer, initCmd bool, options ...cmdOption)

Source from the content-addressed store, hash-verified

72}
73
74func cmdBuilderWithInit(parent *Command, cr CmdRunner, cliText, shortdesc string, longdesc string, out io.Writer, initCmd bool, options ...cmdOption) *Command {
75 cc := &cobra.Command{
76 Use: cliText,
77 Short: shortdesc,
78 Long: longdesc,
79 }
80
81 c := &Command{Command: cc}
82
83 if parent != nil {
84 parent.AddCommand(c)
85 }
86
87 for _, co := range options {
88 co(c)
89 }
90
91 // This must be defined after the options have been applied
92 // so that changes made by the options are accessible here.
93 c.Command.Run = func(cmd *cobra.Command, args []string) {
94 c, err := NewCmdConfig(
95 cmdNS(c),
96 &doctl.LiveConfig{},
97 out,
98 args,
99 initCmd,
100 )
101 checkErr(err)
102
103 c.Command = cmd
104
105 err = cr(c)
106 checkErr(err)
107 }
108
109 if cols := c.fmtCols; cols != nil {
110 formatHelp := fmt.Sprintf("Columns for output in a comma-separated list. Possible values: `%s`.",
111 strings.Join(cols, "`"+", "+"`"))
112 AddStringFlag(c, doctl.ArgFormat, "", "", formatHelp)
113 AddBoolFlag(c, doctl.ArgNoHeader, "", false, "Return raw data with no headers")
114 }
115
116 return c
117
118}

Callers 5

ServerlessFunction · 0.85
AuthFunction · 0.85
ServerlessExtrasFunction · 0.85
appsSpecFunction · 0.85
CmdBuilderFunction · 0.85

Calls 7

NewCmdConfigFunction · 0.85
cmdNSFunction · 0.85
checkErrFunction · 0.85
AddStringFlagFunction · 0.85
AddBoolFlagFunction · 0.85
AddCommandMethod · 0.80
SprintfMethod · 0.80

Tested by

no test coverage detected