diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-16 17:30:34 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-16 17:30:34 -0400 |
commit | 5dc8f6bccb89bc952d924cf615435c0185168a27 (patch) | |
tree | ca23445faa855ff1fa52171072b7903d4aea3cdc /src/option.h | |
parent | b7f2a95c1f630d1246afa4b7f847435d62c9341e (diff) | |
download | fork-ledger-5dc8f6bccb89bc952d924cf615435c0185168a27.tar.gz fork-ledger-5dc8f6bccb89bc952d924cf615435c0185168a27.tar.bz2 fork-ledger-5dc8f6bccb89bc952d924cf615435c0185168a27.zip |
Report better errors if options are missing args
Diffstat (limited to 'src/option.h')
-rw-r--r-- | src/option.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/option.h b/src/option.h index 7deb5f58..b201cb72 100644 --- a/src/option.h +++ b/src/option.h @@ -90,10 +90,17 @@ public: string desc() const { std::ostringstream out; + out << "--"; + for (const char * p = name; *p; p++) { + if (*p == '_') { + if (*(p + 1)) + out << '-'; + } else { + out << *p; + } + } if (ch) - out << "--" << name << " (-" << ch << ")"; - else - out << "--" << name; + out << " (-" << ch << ")"; return out.str(); } @@ -136,10 +143,13 @@ public: virtual void handler_thunk(call_scope_t&) {} virtual void handler(call_scope_t& args) { - if (wants_arg) + if (wants_arg) { + if (args.empty()) + throw_(std::runtime_error, "No argument provided for " << desc()); on(args[0]); - else + } else { on(); + } handler_thunk(args); } |