Git Product home page Git Product logo

cmdparser's Introduction

Hi there ๐Ÿ‘‹!

My name is Florian Rappl and I am a solution architect from Munich, Germany.

  • ๐Ÿ”ญ Iโ€™m currently working on Piral, AngleSharp, Electron.NET, and a few other projects
  • ๐ŸŒฑ Iโ€™m currently learning a bit of everything
  • ๐Ÿ‘ฏ Iโ€™m looking to collaborate on micro frontends
  • ๐Ÿค” Iโ€™m looking for help with expanding Piral
  • ๐Ÿ’ฌ Ask me about anything, especially as long as its about web dev or micro frontends in particular
  • ๐Ÿ“ซ How to reach me: Twitter and LinkedIn
  • ๐Ÿ˜„ Pronouns: He/him
  • โšก Fun fact: Just call me Flo (similar to Workflow, but more like Funflow)

Articles

Contributions

GitHub Streak

Repository Languages

Trophy Collection

cmdparser's People

Contributors

akshat-oke avatar benhenning avatar biroder avatar cngzhnp avatar emankov avatar farzonl avatar ferkulat avatar florianrappl avatar tlanc007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmdparser's Issues

Positional Arguments

Hi, is it possible to get positional arguments?

myapp --someflag -a2 FILE1 FILE2 FILE3...

For example.

Backward compatibility

Hey that was nifty, thanks!

Working great with C++ 11 and above, I wonder how can this be used without C++11, and should backward compatibility be addressed?

I'd like to pick that up and give you a PR.

How to get a flag

Hi,

Sorry for bugging you, but I have a question. So I've been reading your code and it seams to me there is no way to handle flags. Could it be?? The behaviour I need is, every time i call -h of --help, all other options are not to be evaluated but the usage() ought to be printed. For that to work I would need to evaluate if the call to -h has been made but it seams there is no way to evaluate the flat , just if a parameter has been assigned to it or not, right? Could you maybe point me to the right direction on how to enable that (if I'm not seeing the option)

thnx

PS great library

PS
PS

I see that this question has been rased for --help option. I mean one can easily add something like:

bool help = false
...
if ( std::find(_arguments.begin(), _arguments.end(), "--help") != _arguments.end() ||
std::find(_arguments.begin(), _arguments.end(), "-h") != _arguments.end())
help = true;
...

if (command->required && !command->handled && help == false) ....

in run() function to quick "fix" the help behaviour.

but i see no flag handling solution so i guess the one does not exist. (This was not a negative critique, the library is really great. Thnx!! I am definitely gonn start using it from now on. plus if i manage to find some time before you I'll definitely integrate the set_flag() option )

Licensing is too restrictive

Hi Florian,
You have a nice command line parsing library here, but it's a bit too restrictive in its licensing (GPLv3: it's incompatible with and imposes upon several other licenses). Would you consider relicensing the library under Public Domain or the MIT license?

Thanks!
Divye

Do you mind tagging a version?

Hello! This is a nice and small library and we'd like to use it in our product, but we need to specify a particular version in the product license attributions. Can you tag some recent stable version? Currently you only have v1.0 which is 4 years old and uses GPLv3 license. Thank you!

help not displayed if required field has not been set

Hi there

Firstly, thank you for this very helpful library.

I found that help was not being outputted if a required argument was not specified on the cmd line. Is this the desired behaviour?

I personally did not want this behaviour so have changed it so that help is always displayed (if -h/--help is specified) but a required argument is not.

I would be happy to create a PR if you wish to view my changes. I just swapped the order in which you check for unhandled required arguments and parse the handled ones in "run". This may screw it up elsewhere as I have not run the tests, but it works for me!

Cheers

Nice work ...

Hello Florian, this is a nice light-weight parser, for which many thanks. I've made a set of changes to allow it to handle Windows UNICODE. Are you interested in a PR?

Memory leak when disabling help

You only erase the command from the list, but don't delete it. Potential fix:

	void disable_help() {
		for (auto command = _commands.begin(); command != _commands.end(); ++command) {
			if ((*command)->name == "h" && (*command)->alternative == "--help") {
				delete  *command;
				_commands.erase(command);
				break;
			}
		}
	}

Tests broken: first `TEST_CASE("Parse help", "[help]")` calls `exit(0)`.

Currently, the tests cannot be run by invoking the test-executable.

This is because the very first test ( "Parse help", "[help]" ) leads to exit(0) being called inside a callback created in void enable_help(). After that, the test executable exits. The checks contained in that test are never executed. Also, no further tests are executed. This means that whenever ( "Parse help", "[help]" ) is included in the list of tests to be run, some or all of the tests will not be run at all, depending on the order of tests.

The callback looks like this:

void enable_help() {
    set_callback("h", "help", std::function<bool(CallbackArgs & )>([this](CallbackArgs &args) {
        args.output << this->usage();
#pragma warning(push)
#pragma warning(disable: 4702)
        exit(0);
        return false;
#pragma warning(pop)
    }), "", true);
}

It seems that this callback really should quit the program when used in user code. Hence, I don't know how to best solve this problem for the unit tests. Perhaps the problematic test case should be removed, especially since it doesn't actually test anything?

As an aside, perhaps the pragma warning modification (which are specific to MSVS compiler) to really be specific to that compiler, e.g., like this:

#if defined(_MSC_VER)
// pragma ...
#endif

Other compilers don't support this and the pragma sometimes becomes a warning in itself, as in "unknown pragma".

Uninitialized scalar field

Minor bug concerning class CmdFunction final : public CmdBase

Coverity scan says line 100:

CID 281693 (#1 of 1): Uninitialized scalar field (UNINIT_CTOR)
2. uninit_member: Non-static class member value is not initialized in this constructor nor in any functions that it calls.

and line 118:

1. member_decl: Class member declaration for value.

but seems to me this member variable is set but never used.

Sign conversion compilation warnings

Not a bug bust just warnings triggered when compiling with -Wsign-conversion option. You should replace int by size_t in two lines:

~Parser() { 
for (size_t i = 0, n = _commands.size(); i < n; ++i) { ...

and

bool run(std::ostream& output, std::ostream& error) { ...
for (size_t i = 0, n = _arguments.size(); i < n; ++i) {

Thanks for this lib !

Parsing hex and octal numbers

Suggest (optional ?) modification of number parsers to the following (so it can also parse hex and octal numbers)

return std::stoi(elements[0]);
to
return std::stoi(elements[0], 0, 0);

valgrind detects leaks with still reachable memory

Hi Florian ! I just discovered right now your lib ! Nice work ! It seems to Valgrind that there are missing calls to delete but memory can be released by the OS. I had no time for longer investigations but it seems to me:
1/ that exit() does not let class destructor to be called :( You have to create and call a release() method called by class destructor and to be called manually before your exit().
2/ disable_help() you call std::vector::erase() but you did not delete the command before.

Adding Catch to the project?

Hello Florian,

I would like to contribute, but Catch is missing.
Maybe you installed it as package to your OS?
Would you mind to add the Catch header to the project?
Either by

  1. just download and commit or
  2. via git submodule?
  3. biicode (I don't know, if this would be possible)

In my projects I prefer case 1.

For cases 1. or 2. I could make a pull request for that. if you want.
For case 3. I don't know biicode enough yet.

Thank you in advance

multiple arguments of the same flag

I am interested in essentially parse a vector of vector. One way I thought about doing it is to simply send in multiple values of the same flag. For example, something like
<my_binary> -v v0_0 v0_1 v0_2 -v v1_0 v1_1 v1_2
Is this possible using your parser? Thanks.

handling of default argument -h

I just stumbled upon this library and wanted to try it out. I'm in a console application in Visual Studio 2015. I included the cmdparser.hpp file as is.
My code is simple:

cli::Parser parser(argc, argv);
parser.run();

I now call my .exe file with parameter -h and the output ends like so:

The parameter h has invalid arguments.
For more help use --help or -h.

What is happening here? How does h have invalid arguments?

In another situation I have one parser.set_required call. When I again call my .exe file with parameter -h the output looks like so:

The parameter i is required.
Name of input file.
For more help use --help or -h.

Why is argument i still required when -h is provided? Why does it not output the help - list of required arguments?

Detection of required arguments and the retrieval with the parser.get method works nicely.

Your sample in the README.md of this repo reads:

cmd.run_and_exit_if_error();

must be

  parser.run_and_exit_if_error();

Thank you for your work.

Allow to specify general program description

Currently, it seems that the command line parser only deals with descriptions of command line parameters.

Most command line parsers allow to specify a general description of what the program does, which is usually displayed in the help text above the argument descriptions. This does not seem to be supported at the moment, although it should be easy to implement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.