From b459d4782dd71f54a9dc03058881dd48830f33e6 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Tue, 7 Feb 2017 15:00:24 -0500 Subject: [PATCH] Making positional types clearer --- CHANGELOG.md | 2 +- include/CLI/App.hpp | 2 +- include/CLI/Option.hpp | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33f1f47f..5507b982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Version 0.3 (in progress) * Supports GCC 4.7 again -* TODO: Support type and set syntax in positionals +* Support type and set syntax in positionals * Changes `setup` for an explicit help bool in constructor/`add_subcommand` diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 5aadd421..26910892 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -547,7 +547,7 @@ public: out << "Positionals:" << std::endl; for(const Option_p &opt : options) if(opt->get_positional() && opt->has_description()) - detail::format_help(out, opt->get_pname(), opt->get_description(), wid); + detail::format_help(out, opt->help_pname(), opt->get_description(), wid); out << std::endl; } diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index f2c4c629..742da56f 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -135,7 +135,6 @@ public: std::string get_pname() const { return pname; } - /// Process the callback bool run_callback() const { if(_validators.size()>0) { @@ -241,6 +240,21 @@ public: } return out.str(); } + + /// pname with type info + std::string help_pname() const { + std::stringstream out; + out << get_pname(); + if(typeval != "") + out << " " << typeval; + if(defaultval != "") + out << "=" << defaultval; + if(get_expected() > 1) + out << " x " << get_expected(); + if(get_expected() == -1) + out << " ..."; + return out.str(); + } /// Produce a flattened vector of results, vs. a vector of vectors. std::vector flatten_results() const {