-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Writing a bash like shell #279
Comments
I would imagine you would make a child command
I'm not sure whether this is right or wrong, but it is one approach. Update : Parse a string into a string array using space as a delimiter, then put it into a string array and do this in a for loop SetArgs manually sets the arguments used in Execute |
I was able to integrate github.com/chzyer/readline with cobra pretty easily. Here is a gist of a shell command that parses the command structure to populate the autocomplete tree and then executes the commands from the readline. (https://gist.github.com/elliotmr/8815e429a91bdc54109eeec9d5a53cbd) Actually, I think there is an opportunity to clean this up and turn it into another library. |
Currently working on a tool that applies the methodology provided by @elliotmr to simplify management of configuration in AWS Parameter Store. I've posted one small revision as a comment on his gist and will aim to contribute some further examples in the near future. |
Still working on this, though I'm running into challenges that may prompt me to go another direction. Though it's possible to get a basic interactive shell running, the challenge that you will run into is that flags will leak between command invocations. For example, if I set a boolean flag (default false) on one invocation, the next invocation will see the flag as default true since the flag library is built on the assumption that flags are only ever used once. I've dug through the source for cobra and pflag looking for a workaround, but we're missing a couple of core features that would allow us to clear flag state (and restore defaults) or otherwise fine-tune the behavior of flags between command invocations. I've come fairly close to building this functionality, but each attempt has been thwarted by one design decision or another. For example:
I think I'll be able to come up with a hack solution, but it appears that a good solution would require some changes to the guts of pflag/cobra. |
@clintoncampbell Did you ever come up with a good solution to this? We're running into this same issue. We wrote our own interactive shell for Cobra (a for loop that calls SetArgs and Execute for each command) and arguments are leaking to other command invocations. "--help" is the easiest way to reproduce this issue. |
I thought I'd leave a comment describing how we finally got around to working around the problem that @clintoncampbell pointed out. What we did was not use the global |
This issue is being marked as stale due to a long period of inactivity |
@robertgrimm is there any solution to this issue in 2020? |
@dkozlov I'm still using the same solution I described in my last comment. It's been working well for us. |
Going to close this issue due to lack of a clear problem (motivated by #1600). Based on the discussion the issue is really more about being able to reset flags to their default value, the bash shell usage is just context. If you think this is still something that would be useful/important to pursue, please create another issue or reopen this one. |
Hello everyone, The project is an integrated console application: Maybe some of you will be interested ! |
Can we do something like the following with this plugin
Essentially have a shell that has it's own commands?
The text was updated successfully, but these errors were encountered: