Skip to content

Commit

Permalink
parse docopts only for parent cmdToRun
Browse files Browse the repository at this point in the history
  • Loading branch information
kindermax committed Feb 17, 2020
1 parent b34577f commit cfd7a66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions commands/command/docopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var DocoptParser = &docopt.Parser{
}

// ParseDocopts parses docopts for command options with args from os.Args
// TODO pass os.Argv explicitly
func ParseDocopts(cmd Command) (docopt.Opts, error) {
// no options at all
if cmd.RawOptions == "" {
Expand Down
18 changes: 11 additions & 7 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ func runCmd(cmdToRun command.Command, cfg *config.Config, out io.Writer, parentN
cmd.Stderr = out
cmd.Stdin = os.Stdin

// parse docopts
opts, err := command.ParseDocopts(cmdToRun)
if err != nil {
return formatOptsUsageError(err, opts, cmdToRun)
isChildCmd := parentName != ""

// parse docopts - only for parent
if !isChildCmd {
opts, err := command.ParseDocopts(cmdToRun)
if err != nil {
return formatOptsUsageError(err, opts, cmdToRun)
}
cmdToRun.Options = command.OptsToLetsOpt(opts)
cmdToRun.CliOptions = command.OptsToLetsCli(opts)
}
cmdToRun.Options = command.OptsToLetsOpt(opts)
cmdToRun.CliOptions = command.OptsToLetsCli(opts)

// setup env for command
cmd.Env = composeEnvs(
Expand All @@ -79,7 +83,7 @@ func runCmd(cmdToRun command.Command, cfg *config.Config, out io.Writer, parentN
convertEnvMapToList(cmdToRun.CliOptions),
convertChecksumToEnvForCmd(cmdToRun.Checksum),
)
if parentName == "" {
if !isChildCmd {
logging.Log.Debugf(
"Executing command\nname: %s\ncmd: %s\nenv:\n%s",
fmt.Sprintf(NoticeColor, cmdToRun.Name),
Expand Down

0 comments on commit cfd7a66

Please sign in to comment.