@@ -191,8 +191,12 @@ struct Cli::Config {
191191 shared_ptr<locale> defLoc = make_shared<locale>();
192192 shared_ptr<locale> numLoc = make_shared<locale>(" " );
193193
194+ // Opt* and value actively being parsed, referenced servicing action
195+ // callbacks.
194196 Cli::OptBase * curOpt = {};
197+ string originalValue;
195198 string newValue;
199+
196200 int exitCode = kExitOk ;
197201 string errMsg;
198202 string errDetail;
@@ -780,7 +784,7 @@ void Cli::newValue(const string & value) {
780784 if (parseBool (v, value)) {
781785 m_cfg->newValue = v ? " 1" : " 0" ;
782786 } else {
783- badUsage (opt, value );
787+ badUsage (opt);
784788 }
785789 }
786790}
@@ -1232,20 +1236,19 @@ void Cli::defParseAction(Cli & cli, OptBase & opt, const string & val) {
12321236
12331237 string desc;
12341238 writeChoicesDetail (&desc, opt.m_choiceDescs );
1235- cli.badUsage (opt, val , desc);
1239+ cli.badUsage (opt, nullptr , desc);
12361240}
12371241
12381242// ===========================================================================
12391243// static
12401244void Cli::argSrcFileRelAction (Cli & cli, OptBase & opt, const string & rel) {
1241- string val = rel;
12421245#ifdef DIMCLI_LIB_FILESYSTEM
12431246 if (opt.srcType () == ArgSrc::kFile ) {
12441247 auto p = fs::u8path (opt.srcName ()).parent_path () / rel;
1245- val = (char *) p.generic_u8string ().c_str ();
1248+ string val = (char *) p.generic_u8string ().c_str ();
1249+ cli.newValue (val);
12461250 }
12471251#endif
1248- defParseAction (cli, opt, val);
12491252}
12501253
12511254// ===========================================================================
@@ -2624,6 +2627,7 @@ Cli & Cli::resetValues() & {
26242627 for (auto && opt : m_cfg->opts )
26252628 opt->reset ();
26262629 m_cfg->curOpt = {};
2630+ m_cfg->originalValue .clear ();
26272631 m_cfg->newValue .clear ();
26282632 m_cfg->parseExit = false ;
26292633 m_cfg->exitCode = kExitOk ;
@@ -2674,7 +2678,17 @@ void Cli::badUsage(
26742678 const string & detail
26752679) {
26762680 string prefix = " Invalid '" + opt.from () + " ' value" ;
2677- return badUsage (prefix, value, detail);
2681+ badUsage (prefix, value, detail);
2682+ }
2683+
2684+ // ===========================================================================
2685+ void Cli::badUsage (
2686+ const OptBase & opt,
2687+ nullptr_t ,
2688+ const string & detail
2689+ ) {
2690+ string prefix = " Invalid '" + opt.from () + " ' value" ;
2691+ badUsage (prefix, m_cfg->originalValue , detail);
26782692}
26792693
26802694// ===========================================================================
@@ -2747,6 +2761,7 @@ bool Cli::parseValue(
27472761 return false ;
27482762 }
27492763 if (ptr) {
2764+ m_cfg->originalValue = ptr;
27502765 m_cfg->newValue = ptr;
27512766 m_cfg->curOpt = &opt;
27522767 opt.doTransforms (*this );
@@ -2756,10 +2771,12 @@ bool Cli::parseValue(
27562771 if (!parseAborted ())
27572772 opt.doChecks (*this );
27582773 } else {
2774+ m_cfg->originalValue .clear ();
27592775 m_cfg->newValue .clear ();
27602776 opt.assignImplicit ();
27612777 opt.doChecks (*this );
27622778 }
2779+ m_cfg->originalValue .clear ();
27632780 m_cfg->newValue .clear ();
27642781 return !parseAborted ();
27652782}
0 commit comments