-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
feat: set and shopts directives #929
Conversation
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.
First look.
I liked the direction here, but adding interp.BashOpts
to mvdan/sh
first would be great IMO.
internal/execext/exec.go
Outdated
// Manually adding bash opts before each command as there is no interp.Shopts | ||
if len(opts.BashOpts) > 0 { | ||
s = append(s, fmt.Sprintf("shopt -s %s", strings.Join(opts.BashOpts, " "))) | ||
} |
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.
I agree on contributing to mvdan/sh adding a interp.BashOpts
option. I think it may be even worth waiting for it to be released before merging this here (but if it takes too long, it's fine to merge as is and adapt later).
@andreynering I've fixed the issues you raised, but haven't had the time to look into the codebase over at mvdan/sh yet. I've opened an issue (mvdan/sh#962) over there instead. Hopefully I (or someone else) will have the time to work on this soon. In the meantime, if you're happy to merge this as-is, I can open another issue to track the improvements once (if) the functionality is added upstream. |
- Rename `shopts` to `shopt` - Move `UniqueJoin` to a more appropriate package - Write documentation - Add entry to README
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.
Yes, let's get this merged and we can improve once mvdan/sh#962 gets implemented.
I've renamed shopts
to shopt
for consistency with the proper builtin. Also added documentation and README entry.
Thanks again!
See go-task/task#929 for details
I love
thanks!!! |
@andreynering Thanks for tidying this up. I forgot to add the docs/schema etc. when marking as ready. I've opened #984 to track the improvements as discussed. |
builtins. This can be added at global, task or command level. | ||
|
||
```yaml | ||
version: '2' |
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.
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.
@marco-m-pix4d good spot! yes, this should be version: '3'
. I'll get this updated.
Summary
This PR adds 2 new directives:
set
-[]string
- Equivalent of the POSIXset
builtinshopts
-[]string
- Equivalent of the Bashshopt
builtinBoth of these directives are available at global, task and command level. See example Taskfile below:
Considerations
mvdan/sh
allows us to set POSIX shell options viainterp.Params()
. However, from what I can tell, there is no equivalent for Bash options. This means that this PR is currently prepending theshopt
builtin before each command whereshopts
are specified. I'm not a huge fan of this and have been looking at contributing a change tomvdan/sh
to add a newinterp.Shopts()
function or similar. I'd love some input from @mvdan on whether this is a good approach.map[string]bool
so that you could enable/disable opts at different levels. However, I came to the conclusion that this level of complexity wasn't really necessary as all the currently supported shell options are disabled by default anyway. Implementing as a[]string
still allows us to enable at each level and I think this covers most use cases. It also keeps the Taskfile looking clean as we can inline the list with[]
.set
andshopts
are definitely up for debate. I wasn't sure about the plurality for example...Currently supported shell options
POSIX (
set
)If you have
gosh
installed, you can find these by runninggosh -c "set -o"
.allexport
a
errexit
e
noexec
n
noglob
f
nounset
u
xtrace
x
pipefail
Bash (
shopt
)If you have
gosh
installed, you can find these by runninggosh -c "shopt"
.expand_aliases
globstar
nullglob
Don't have
gosh
?If you don't have
gosh
installed, you can use the following Taskfile to get these lists: