| 199 | } |
| 200 | |
| 201 | func ParseArgs(cobraCmd *cobra.Command, globalFlags *flags.GlobalFlags, log log.Logger) ([]string, error) { |
| 202 | index := -1 |
| 203 | for i, v := range os.Args { |
| 204 | if v == cobraCmd.Use { |
| 205 | index = i + 1 |
| 206 | break |
| 207 | } |
| 208 | } |
| 209 | if index == -1 { |
| 210 | return nil, fmt.Errorf("error parsing command: couldn't find %s in command: %v", cobraCmd.Use, os.Args) |
| 211 | } |
| 212 | |
| 213 | // check if is help command |
| 214 | osArgs := os.Args[:index] |
| 215 | if len(os.Args) == index+1 && (os.Args[index] == "-h" || os.Args[index] == "--help") { |
| 216 | return nil, cobraCmd.Help() |
| 217 | } |
| 218 | |
| 219 | // enable flag parsing |
| 220 | cobraCmd.DisableFlagParsing = false |
| 221 | |
| 222 | // apply extra flags |
| 223 | _, err := flagspkg.ApplyExtraFlags(cobraCmd, osArgs, true) |
| 224 | if err != nil { |
| 225 | return nil, err |
| 226 | } |
| 227 | |
| 228 | if globalFlags.Silent { |
| 229 | log.SetLevel(logrus.FatalLevel) |
| 230 | } else if globalFlags.Debug { |
| 231 | log.SetLevel(logrus.DebugLevel) |
| 232 | } |
| 233 | |
| 234 | args := os.Args[index:] |
| 235 | return args, nil |
| 236 | } |
| 237 | |
| 238 | // LoadCommandsConfig loads the commands config |
| 239 | func (cmd *RunCmd) LoadCommandsConfig(f factory.Factory, configLoader loader.ConfigLoader, configOptions *loader.ConfigOptions, log log.Logger) (devspacecontext.Context, error) { |