-
Notifications
You must be signed in to change notification settings - Fork 18
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
Passing arguments #9
Comments
I'm in the same boat, not sure how to parse the supplied args. |
Clir supports subcommands and named arguments. The docs have all the examples as well as the examples directory. In your example, you'd create a subcommand called
Now you can |
Yes, we were hoping to do |
This would be 🔥. |
Alright, after some testing have realized we can directly call os.Args[], so as long as we know the position (which could be a major issue), you can fulfill the requirements. If you don't know the position, then you will need to do some string searching and cutting.
|
So maybe something to add to the library that stores all args supplied after the subcommand? Although all of my actions are functions in another library, so either global or you could implement the changes by amichael7 and their "CustomAction" implementation to pass them, or some other method. |
I'll implement something better than accessing os.Args today 👍 |
I've pushed an update that addresses this. There's an example in |
Now tagged as |
That was fast! Unfortunately it doesn't work for my use case. Consider this example:
And the output:
|
Ah, subcommands.... yes.... I can sort that out. |
Opened a pull request in case you haven't done it yet. Was curious if you were planning on adding "required" tags or not to the library? That is about the only other thing I need (well can do this other ways, but would be nice to have) at this time. |
Hmm, looking at it you wrap the |
To be honest I didn't want to overly complicate the library. It's just meant to be for quick'n'easy clis. Adding required might be tricky. I'm happy to consider any PRs 👍 @Wulfheart - does this sort your problem out now? |
@leaanthony Somehow yes. Even though something like a required number of arguments would really be helpful. 😉
In this case I'd like the cli to define required arguments (in this case |
@Wulfheart IDK, after some experimentation I think @leaanthony might be right that required is best handled elsewhere. If you look at your case something like this would be simple and effective:
This kind of thing requires the flags to be first, but I think that is good practice anyway. I do have required working on my current git branch, but not sure how much I like it. However @leaanthony I do have a pull request for shorcuts which I do think are very useful and nice. Does require a lot of changes though. |
Is it possible to pass arguments to the cli?
E.g. I have a command like
cli create test
and I'd like the create cmd know that it has to create something named e.g. test.The text was updated successfully, but these errors were encountered: