Skip to content
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

Unable to add short version of option #132

Open
AntonioCS opened this issue Jun 8, 2020 · 10 comments
Open

Unable to add short version of option #132

AntonioCS opened this issue Jun 8, 2020 · 10 comments

Comments

@AntonioCS
Copy link

AntonioCS commented Jun 8, 2020

I have the following:

static const char static const char USAGE[] =[] =
R"(Usage: my_program [-ho <file>] [--output=<file>] [--remove_comments] [--no_separators] [--no_timestamp] [--silent] <path>

    -h --help                   show this
    -o <file> --output=<file>   specify output file [default: ./default.h]
    --remove_comments           remove one line comments from the header files
    --no_separators             don't add // <filename> START|END separators
    --no_timestamp              don't add timestamp
    --silent                    no info text
)";

I then call my_program: my_program.exe --output=test ./dir/
this gives me an error of Arguments did not match expected patterns

If I remove the -o <file> so that USAGE becomes:

static const char USAGE[] =
R"(Usage: my_program [-h] [--output=<file>] [--remove_comments] [--no_separators] [--no_timestamp] [--silent] <path>

    -h --help                   show this
    --output=<file>             specify output file [default: ./allinone.h]
    --remove_comments           remove one line comments from the header files
    --no_separators             don't add // <filename> START|END separators
    --no_timestamp              don't add timestamp
    --silent                    no info text
)";

All works as expected. Shouldn't the -o <file> work?

@jaredgrubb
Copy link
Member

I see this which looks wrong [-ho <file>] ... is that causing the problem?

@AntonioCS
Copy link
Author

I don't know. The error message is just the generic: params are not right..
What is wrong exactly? I want to be able to pass a file either by doing -o or --output=

@AntonioCS
Copy link
Author

I also want it to be mandatory that if you pass -o or --output that you pass

@AntonioCS
Copy link
Author

To note if I do this:

my_program -o file path

I get the following error:

Unexpected argument: -o, file, path

I also get an error with --output=file

I have tried:

- -o <file> --output=<file>       specify output file [default: ./default.h]
- -o file --output=file       specify output file [default: ./default.h]
- -o --output=file       specify output file [default: ./default.h]

Is what I want impossible?

@indianakernick
Copy link
Contributor

indianakernick commented Jun 11, 2020

What you’re trying to do is not impossible. You just haven’t got the syntax quite right. Try this:

Usage:
  my_program [--output=<file>]

Options:
  -o, --output <file>  specify output file [default: ./default.h]

I encourage you to play around with this online tool. It’s great for prototyping.

@AntonioCS
Copy link
Author

@Kerndog73
So following your suggestion I have changed it to:

static const char USAGE[] =
R"(Usage: my_program [-h] [--output=<file>] [--remove_comments] [--no_separators] [--no_timestamp] [--silent] [path]

Arguments:
    [path]                      path to directory of header files
  
Options:
    -h --help                   show this
    -o, --output <file>         specify output file [default: ./default.h]
    --remove_comments           remove one line comments from the header files
    --no_separators             don't add // <filename> START|END separators
    --no_timestamp              don't add timestamp
    --silent                    no info text
)";

Added Arguments and Options section.
I calling the program like:

my_program --output=file path

Still getting the same error:

Unexpected argument: --ouput=file, path
Usage: onlyoneheader [-h] [--output=<file>] [--remove_comments] [--no_separators] .........

@indianakernick
Copy link
Contributor

That’s because file path is two separate arguments. You need to use a backslash. file\ path.

@AntonioCS
Copy link
Author

Not sure if I follow you.. but I did

my_program --ouput=file\ path

and got:

Unexpected argument: --ouput=file\, path

Not exactly sure why this is breaking now... I mean.. this at least worked before with just --output=file path (when I removed the -o stuff) and now it's breaking...
Is there a way to get some better error messages? Like -vvv for errors?

@jaredgrubb
Copy link
Member

You spelled it ouput in the example you typed (missing a 't'). Does that fix it?

No, the errors are not helpful and would be super helpful (but super hard :( ) .. there is an Issue open fort hat.

@AntonioCS
Copy link
Author

@jaredgrubb this is what I get for trying to program late at night!
That was indeed the issue. So to provide full context here is what I have currently:

static const char USAGE[] =
R"(Usage: my_program [-h] [--output=<file>] [--remove_comments] [--no_separators] [--no_timestamp] [--silent] <path>

Arguments:
    <path>                      path to directory of header files
  
Options:
    -h --help                   show this
    -o --output=<file>          specify output file [default: ./default.h]
    --remove_comments           remove one line comments from the header files
    --no_separators             don't add // <filename> START|END separators
    --no_timestamp              don't add timestamp
    --silent                    no info text
)";

Now the -o is not longer a boolean option and everything works.
One thing I would like to know is if it's possible to add back the -o to the Usage part or does it only have to show up in the Options like I guess the --help does?
Possibly also add a few more examples that have this exact scenario? Found some examples that were similar but don't think they were exactly like what I had.

Thanks @jaredgrubb , @Kerndog73. for helping me with this, was really going crazy.

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

No branches or pull requests

3 participants