-
Notifications
You must be signed in to change notification settings - Fork 14
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
changed command execution logic. Closes #7 #14
Open
nithin-bose
wants to merge
1
commit into
yosssi:master
Choose a base branch
from
nithin-bose:command-execution-changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This isn't crossplatform solution, is 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.
No its not.... which is probably why its not merged yet. I am mostly on linux/mac and this solution works. I need environment variables to be parsed. I am open to suggestions.
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.
How about use of regexps? Not the final version of code, just the idea:
And then update the existing code:
After that all values in a
${SOME_NAME}
form will be replaced by the appropriate environment variables.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.
its not just env variables, it could be another command as well, which could have a env variable inside.... i am pretty weary of using regex for that.... too many cases to check and it could get really complicated real fast.
I am personally running sub commands inside $() which caused the issue in the first place
I was thinking of maybe
runtime.GOOS
maybe)I really dont want to over complicate stuff though
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'm not sure I'm following. Can you illustrate your words by an example of such command?
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.
something like:
docker exec -it $(docker-compose ps -q $TEST) echo "hi"
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.
So what you want is support of shell commands, not just Environment variables (you didn't include this detail in the #14 PR's description, it is however in the title of #7 which I missed).
The right (cross-platform) way for adding support of env vars is
os.ExpandEnv
(yeah, you don't even need to use regexps).For subcommands I would go with the parsing of
(
and)
. Not an easy fix, you'll have to use a stack data structure and parse & execute every subcommand one-by-one. But cross-platformability worth it.For support of the shell commands, I would add a new key to the configuration file (what you've mentioned in your comment above). But definitely not break the work of the tool for users of other platforms.
Alternatively (if you do not have to use subcommands / shell commands too often), you can just create a shell script (e.g.
smth.sh
):And then use it as follows:
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.
My master branch has this merged and kind of serves my purpose. I just thought a PR for the same might be good. I understand the cross compatibility issue but just threw it out here for what its worth.
If anybody else needs this feature too, I think adding an optional tag, like
prefix_command
(at global scope would be good enough for me) to the yaml/json file would be the simplest and elegant solution without breaking cross platform support/functionality.I am a "heavy" user of goat and really glad i found it. I have around 15 watchers and quite a few init tasks all of which needs subcommands/ env variables, writing script files for all of them would not be practical.
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've discovered a package for exactly this use-case: https://github.com/mattn/go-shellwords
It supports env vars, subcommands (that are run in SHELL but in a cross-platform way), quotes. The change required for its use is:
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.
awesome find.... let me check it out.