Giter Site home page Giter Site logo

getopt's People

Contributors

genuineaster avatar lundmark avatar wc-duck 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

getopt's Issues

Parsing a valid argument with GETOPT_OPTION_TYPE_NO_ARG fails

If you have an argument that's supposed to have no arguments, the getopt_next function still tries to find one. If that's something that doesn't start with a '-' it's considered an argument and an error is returned ("!"). I would expect that if something is TYPE_NO_ARG, whatever comes after should be ignored.

Example: { "foo", 0, GETOPT_OPTION_TYPE_NO_ARG, nullptr, 'f', "do foo things", ""}
Command line that fails: " --foo banana"
Command line that works: " --foo --banana"

Note that the correct argument is actually found, but disqualified with the comment
/* these types should have no argument, usage error! */

char** in getopt_create_context

In c++ main signature uses char** not const char**. I got compilation error because char** can not be converted to const char** that is accepted by getopt_create_context.

Bug or misunderstanding

If you add this test to the getopt_tests.cpp:

TEST bug_compound_flags()
{
	static const getopt_option_t bug_option_list[] = 
	{
		{ "input", 		   0x0, GETOPT_OPTION_TYPE_REQUIRED, 0x0, 'i', "help input", "input value" },
		{ "input-variant", 0x0, GETOPT_OPTION_TYPE_REQUIRED, 0x0, 'I', "help input-variant", "input variant" },
		GETOPT_OPTIONS_END
	};

	const char* argv[] = { "dummy_prog", "--input", "Input Value", "--input-variant", "Input Variant" };
	int argc = (int)ARRAY_LENGTH( argv );

	getopt_context_t ctx;
	int err = getopt_create_context( &ctx, argc, argv, bug_option_list );
	ASSERT_EQ( 0, err );

	int opt;

	int found_input = 0;
	int found_input_variant = 0;
	static char fail_msg[512];

	while( ( opt = getopt_next( &ctx ) ) != -1 )
	{
		switch( opt )
		{
			case 'i': { found_input = 1; ASSERT_STR_EQ("Input Value", ctx.current_opt_arg); break; }
			case 'I': { found_input_variant = 1; ASSERT_STR_EQ("Input Variant", ctx.current_opt_arg); break; }
			default:
				{
					snprintf(fail_msg, 512, "unexpected op '%c' '%s'", opt, ctx.argv[ctx.current_index]);
					FAILm(fail_msg);
				}
				break;
		}
	}

	ASSERT_EQ(1, found_input);
	ASSERT_EQ(1, found_input_variant);

	return 0;
}

I had an issue when using this with compound arguments that have overlapping elements. Attempting to write a bug to repro it, I get a new issue, where this will fail to parse, treating "Input Variant" as an argument.

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.