Skip to content

Instantly share code, notes, and snippets.

@slegroux
Created April 9, 2020 01:49
Show Gist options
  • Save slegroux/20a77a0f44685f1e070fce9a7daed641 to your computer and use it in GitHub Desktop.
Save slegroux/20a77a0f44685f1e070fce9a7daed641 to your computer and use it in GitHub Desktop.
parse command line arguments
int ReadOpts(int argc, char* argv[]){
try {
const char *usage = "test options parser";
kaldi::ParseOptions po(usage);
bool use_i = false;
po.Register("use-i", &use_i, "use i bool");
po.Read(argc, argv);
cout<<po.NumArgs()<<endl;
if (po.NumArgs() != 1) {
po.PrintUsage();
exit(1);
return(-1);
}
std::string fn = po.GetArg(1);
cout<<"ARG 1: "<<fn<<endl;
return(0);
} catch(const std::exception& e) {
std::cerr << e.what();
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment