Skip to content

Change to support nested cmd options based on top level commands#22

Merged
FlorianRappl merged 1 commit intoFlorianRappl:masterfrom
farzonl:feature/customization
Dec 7, 2020
Merged

Change to support nested cmd options based on top level commands#22
FlorianRappl merged 1 commit intoFlorianRappl:masterfrom
farzonl:feature/customization

Conversation

@farzonl
Copy link
Copy Markdown
Contributor

@farzonl farzonl commented Dec 6, 2020

I first made this change Tue Oct 31 17:11:24 2017 -0400. And just now realized I never tried to upstreamed this. I've found this really useful and if possible would like to upstream. This is an example of my use case from them:

class AutoCLI
{
private:
	std::unique_ptr<BaseCLIParser> CliParser;
	void initParser(int argc, char** argv)
	{
		cli::Parser parser(argc, argv);
	
		if (parser.doesArgumentExist(DecryptCLIParser::name, "--" + DecryptCLIParser::altName))
		{
			CliParser = std::unique_ptr<BaseCLIParser>(new DecryptCLIParser(argc, argv));
			return;
		}

		if (parser.doesArgumentExist(EncryptCLIParser::name, "--" + EncryptCLIParser::altName))
		{
			CliParser = std::unique_ptr<BaseCLIParser>(new EncryptedDataMarkingsCLIParser(argc, argv));
			return;
		}
	}
public:
	AutoCLI(int argc, char** argv)
	{
		initParser(argc, argv);
		
		if (CliParser)
		{
			CliParser->executeAction();
		}
	}
};

essentially I wanted a light\simple way to check the arguments lists before deciding which parser to invoke.

…und this limitation it would be useful to query the parsed arguments before we run the comparison against the available commands. This change lets one make such a determination
Copy link
Copy Markdown
Owner

@FlorianRappl FlorianRappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense - thanks a lot! 🍻

@FlorianRappl FlorianRappl merged commit f65e587 into FlorianRappl:master Dec 7, 2020
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

Successfully merging this pull request may close these issues.

2 participants