Code: Select all
./myApp --version
Code: Select all
myApp v0.1.x
myApp's description...
Code: Select all
./myApp --version
Code: Select all
myApp v0.1.x
myApp's description...
Is one of them better than the other, in terms of performance or something?doublemax wrote: ↑Sat Jul 24, 2021 9:30 am wxCmdLineParser
https://docs.wxwidgets.org/trunk/classw ... arser.html
A few of the sample use it, e.g. the webview sample to pass an URL to open.
Or you can directly use wxAppConsole::argc / wxAppConsole::argv like you might be used to:
https://docs.wxwidgets.org/trunk/classw ... 31a5e8bfc5
Code: Select all
void App::OnInitCmdLine(wxCmdLineParser& parser)
{
wxApp::OnInitCmdLine(parser);
parser.AddSwitch("v", "version", "Shows the application version", 0);
parser.Parse(true);
}
bool App::OnCmdLineParsed(wxCmdLineParser& parser)
{
if (!wxApp::OnCmdLineParsed(parser))
return false;
if (parser.Found("version"))
std::cout << "SampleHive v0.8.4_alpha.1" << std::endl;
return true;
}
Code: Select all
parser.AddSwitch("a", "another option", "Shows some output", 0);
parser.Parse(true);
parser.AddSwitch("b", "another option", "Shows some output", 0);
parser.Parse(true);
parser.AddSwitch("c", "another option", "Shows some output", 0);
parser.Parse(true);
Return "false" from App::OnCmdLineParsed or App::OnInit.This does work, but the application starts as soon as it prints the version, can I tell it don't run the app when specific arguments are passed?
You only need to call Parse() once at the end.and so on..?
Like this?Return "false" from App::OnCmdLineParsed or App::OnInit.
Code: Select all
bool App::OnCmdLineParsed(wxCmdLineParser& parser)
{
if (!wxApp::OnCmdLineParsed(parser))
return false;
if (parser.Found("version"))
std::cout << "SampleHive v0.8.4_alpha.1" << std::endl;
return false; // <-------
}
I see.You only need to call Parse() once at the end.
Yes, but of course conditionally, depending on whether you want the app to exit or not.apoorv569 wrote: ↑Sat Jul 24, 2021 3:55 pmLike this?Return "false" from App::OnCmdLineParsed or App::OnInit.Code: Select all
bool App::OnCmdLineParsed(wxCmdLineParser& parser) { if (!wxApp::OnCmdLineParsed(parser)) return false; if (parser.Found("version")) std::cout << "SampleHive v0.8.4_alpha.1" << std::endl; return false; // <------- }
Okay, thank you!doublemax wrote: ↑Sat Jul 24, 2021 5:57 pmYes, but of course conditionally, depending on whether you want the app to exit or not.apoorv569 wrote: ↑Sat Jul 24, 2021 3:55 pmLike this?Return "false" from App::OnCmdLineParsed or App::OnInit.Code: Select all
bool App::OnCmdLineParsed(wxCmdLineParser& parser) { if (!wxApp::OnCmdLineParsed(parser)) return false; if (parser.Found("version")) std::cout << "SampleHive v0.8.4_alpha.1" << std::endl; return false; // <------- }