From 4b17ba155568a394373f6baba40e8b5d5281ccdb Mon Sep 17 00:00:00 2001 From: graehl Date: Fri, 9 Jul 2010 16:04:07 +0000 Subject: cdec --compgen bash completions generation git-svn-id: https://ws10smt.googlecode.com/svn/trunk@199 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/cdec.cc | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'decoder') diff --git a/decoder/cdec.cc b/decoder/cdec.cc index 79d51939..bcba1409 100644 --- a/decoder/cdec.cc +++ b/decoder/cdec.cc @@ -76,6 +76,19 @@ shared_ptr make_ff(string const& ffp,bool verbose_feature_funct return pf; } +// print just the --long_opt names suitable for bash compgen +void print_options(std::ostream &out,po::options_description const& opts) { + typedef std::vector< shared_ptr > Ds; + Ds const& ds=opts.options(); + out << '"'; + for (unsigned i=0;ilong_name(); + } + out << '"'; +} + + void InitCommandLine(int argc, char** argv, po::variables_map* confp) { po::variables_map &conf=*confp; po::options_description opts("Configuration options"); @@ -135,6 +148,7 @@ void InitCommandLine(int argc, char** argv, po::variables_map* confp) { ("config,c", po::value(), "Configuration file") ("help,h", "Print this help message and exit") ("usage,u", po::value(), "Describe a feature function type") + ("compgen", "Print just option names suitable for bash command line completion builtin 'compgen'") ; po::options_description dconfig_options, dcmdline_options; @@ -142,6 +156,12 @@ void InitCommandLine(int argc, char** argv, po::variables_map* confp) { dcmdline_options.add(opts).add(clo); po::store(parse_command_line(argc, argv, dcmdline_options), conf); + if (conf.count("compgen")) { + print_options(cout,dcmdline_options); + cout << endl; + exit(0); + } + ShowBanner(); if (conf.count("config")) { const string cfg = str("config",conf); cerr << "Configuration file: " << cfg << endl; @@ -151,12 +171,13 @@ void InitCommandLine(int argc, char** argv, po::variables_map* confp) { po::notify(conf); if (conf.count("list_feature_functions")) { - cerr << "Available feature functions (specify with -F):\n"; + cerr << "Available feature functions (specify with -F; describe with -u FeatureName):\n"; global_ff_registry->DisplayList(); cerr << endl; exit(1); } + if (conf.count("usage")) { cout<usage(str("usage",conf),true,true)<