Skip to content

[Question] How to have global parameters #257

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

Closed
gep13 opened this issue Oct 28, 2015 · 8 comments
Closed

[Question] How to have global parameters #257

gep13 opened this issue Oct 28, 2015 · 8 comments
Labels

Comments

@gep13
Copy link

gep13 commented Oct 28, 2015

I was hoping that someone will be able to help me, with what I am referring to as global parameters, but this might be known under a different name.

When parsing my input arguments, I want to have an option to include things like a -v argument, which version parsed, will print out the version number of my command line tool. In addition, I want to be able to have verbs for doing specific pieces of functionality, like transform, and then have additional arguments for this command.

Individually, I can get this to work, i.e. have an Option for -v, and have a VerbOption for transform, however, I don't seem to be able to combine them. Am I missing something?

So to recap, what I would like to be able to do is:

my.exe -v

my.exe transform -i "c:/temp/input.xml" -o "c:/temp/output.html"

Is this possible?

Each time I try it, my Version Option is always false.

NOTE: I am using CommandLineParser 1.9.71.

@gep13
Copy link
Author

gep13 commented Oct 28, 2015

I have just looked at the pre-release version of this project, and it looks like it included a default --version which is exactly what I am looking for 👍 Is there any way to alter this so that it also supports -v?

@gsscoder
Copy link
Owner

gsscoder commented Nov 2, 2015

#250 explains why I'm replying late...

@gep13, for the moment 2.0.*-beta (very close to be promoted RC and than STABLE), doesn't support short options name for built-in --help and --version.

This choice is conventional and based on standard *nix utility based that implements getopt() conventions.

I don't think this will be changed, but you can do this in a custom fork with easy.

In Text/HelpText.cs two private methods handle these built-in options MakeHelpEntry() and MakeVersionEntry().
I can link one of it but if sources change the line number may vary.

Let's take MakeVersionEntry: just replace string.Empty with "v" as first parameter of OptionSpecification.NewSwitch and you'll be able to print out version as you ask.

I hope this helped. :)

@gep13
Copy link
Author

gep13 commented Nov 2, 2015

@gsscoder yip, I had already read that issue, so I appreciate you taking the time to get back to me!

I guess the reason that I was asking was that with some other tools, like node, npm, gulp, bower, etc, I can run the -v parameter, and get some immediate information about the version of that tool:

image

So, for the sake of consistency, I wanted to add the same to my console applications.

I am a Windows guy, so I am not clear on what you are referring to when you say:

*nix utility based that implements getopt() conventions.

But I will take your word for it 😄

I will have a think about whether I want to take a fork for commandline to get what I want. Thanks again.

@gsscoder
Copy link
Owner

gsscoder commented Nov 8, 2015

@gep13, consistency is always a good thing, nowadays a lot of terminal commands mix a lot of styles allowing long options with a single dash and other things.

Requesting version with a short option is not really so out-of-standard and after 2.0 reaches STABLE status this choice can be re-evaluated.

There's another "philosophical" choice in implementing built-in --help and --version without short option character defined and this is to allowing user commands with h and v.

Now we can open a discussion about if this makes sense or not... For what I can observe, more a terminal command stick to "common standard" and more exposes these two commands only as long options.

Thanks for starting an interesting discussion, not only code submission allow a project to grow... :)

So we can rethink this after 2.0 reaches STABLE status, as said.

Thank you again.

@gep13
Copy link
Author

gep13 commented Nov 8, 2015

Sounds like a plan to me :-)

As a side note, if I wanted to add some additional top level arguments, similar to --help and --version how can I do this, without re-compiling commandline? Or can I? Everything I tried didn't seem to work.

Thanks again!

@nemec
Copy link
Collaborator

nemec commented Nov 10, 2015

You could add a new verb for each. --help and --version are just built-in verbs.

@gep13
Copy link
Author

gep13 commented Nov 10, 2015

@nemec said...
You could add a new verb for each. --help and --version are just built-in verbs.

Ah, of course, thank you! I think I was overthinking the problem 😄

@alexanderfast
Copy link
Collaborator

Problem solved, closing this. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants