(parent *Command, cr CmdRunner, cliText, shortdesc string, longdesc string, out io.Writer, initCmd bool, options ...cmdOption)
| 72 | } |
| 73 | |
| 74 | func 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 | } |
no test coverage detected