-
-
Notifications
You must be signed in to change notification settings - Fork 117
Allow Custom CLI commands to be any (complex) shell commands #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
... using mvdan.cc/sh/v3's shell parser and interpreter. Also execute "valueCommand commands" the same way when defining environment variables for custom CLI commands.
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stoned thanks again.
Can you please explain what issues you are solving and what is not possible with the current implementation?
Note that currently command steps support complex scripts using https://yaml-multiline.info, e.g.
steps:
- touch ${KUBECONFIG}
- >
aws eksupdate-kubecfg
--cluster-name {{ .Flags.environment }}-{{ .Flags.stage }}-eks-cluster
--aws-profile xxx-gbl-{{ .Flags.stage }}-helm
If the library adds something what is not currently supported, we'll consider it.
We don't want to add a 3rd-party library just b/c it's fancy. Many issues with those 3rd-party libraries, they have bugs we we would encounter later in some cases, they change, they break, they go obsolete (we fixed a few issues like that recently). The more we have them, the more difficult to maintain the whole system.
The function
The support of any shell command without using a library like mvdan/sh if of course possible, and I can provide an alternate implementation if you prefer. |
That's correct, commands separated by I'll review the PR little bit later. Did you test it by running on the command-line? For example, all the currently defined commands in https://github.com/cloudposse/atmos/blob/master/atmos.yaml#L69 should work. Thanks |
The commands mentioned do work, albeit some defined stacks or component do have problems, like for example:
|
And the example could now use a bit of quoting as a shell process is now involved in the steps execution... |
This could help debugging failing commands ;-)
A simpler and incomplete (there is no Windows support for example, unless "Git Bash"/MKSYS/WSL/whatever is used) alternative implementation could be along these lines. Would you prefer something like that ? |
the component Please use |
internal/exec/shell_utils.go
Outdated
|
||
runner, err := interp.New( | ||
interp.Dir(dir), | ||
interp.Env(expand.ListEnviron(append(os.Environ(), env...)...)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stoned you removed
commandToRun := os.ExpandEnv(commandTmpl)
which is used to replace ${var} or $var in the command steps at runtime according to the values of the current environment variables.
Does interp.Env(expand
do the same thing?
Also, we prob need to simplify
interp.Env(expand.ListEnviron(append(os.Environ(), env...)...)),
by using a local var b/c it's difficult to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, mvdan.cc/sh/v3/interp.Env() will setup the environment to use: there is no need to have os.ExpandEnv() making its own substitutions.
And, yes, I will rewrite the call to interp.Env() to be, hopefully, simpler to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stoned thanks again for the PR, LGTM, a few nitpicks, please see comments
OK, got it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @stoned
what
why
references
Misc
ExecuteShellCommandAndReturnOutput
is no longer used and may be removed.executeWorkflowSteps
in a similar way. Would that make sense ?