| 4222 | |
| 4223 | template<typename ConfigT> |
| 4224 | class CommandLine { |
| 4225 | |
| 4226 | struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties { |
| 4227 | Arg() {} |
| 4228 | Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {} |
| 4229 | |
| 4230 | using CommonArgProperties<ConfigT>::placeholder; // !TBD |
| 4231 | |
| 4232 | std::string dbgName() const { |
| 4233 | if( !longName.empty() ) |
| 4234 | return "--" + longName; |
| 4235 | if( !shortNames.empty() ) |
| 4236 | return "-" + shortNames[0]; |
| 4237 | return "positional args"; |
| 4238 | } |
| 4239 | std::string commands() const { |
| 4240 | std::ostringstream oss; |
| 4241 | bool first = true; |
| 4242 | std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end(); |
| 4243 | for(; it != itEnd; ++it ) { |
| 4244 | if( first ) |
| 4245 | first = false; |
| 4246 | else |
| 4247 | oss << ", "; |
| 4248 | oss << "-" << *it; |
| 4249 | } |
| 4250 | if( !longName.empty() ) { |
| 4251 | if( !first ) |
| 4252 | oss << ", "; |
| 4253 | oss << "--" << longName; |
| 4254 | } |
| 4255 | if( !placeholder.empty() ) |
| 4256 | oss << " <" << placeholder << ">"; |
| 4257 | return oss.str(); |
| 4258 | } |
| 4259 | }; |
| 4260 | |
| 4261 | typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr; |
| 4262 | |
| 4263 | friend void addOptName( Arg& arg, std::string const& optName ) |
| 4264 | { |
| 4265 | if( optName.empty() ) |
| 4266 | return; |
| 4267 | if( Detail::startsWith( optName, "--" ) ) { |
| 4268 | if( !arg.longName.empty() ) |
| 4269 | throw std::logic_error( "Only one long opt may be specified. '" |
| 4270 | + arg.longName |
| 4271 | + "' already specified, now attempting to add '" |
| 4272 | + optName + "'" ); |
| 4273 | arg.longName = optName.substr( 2 ); |
| 4274 | } |
| 4275 | else if( Detail::startsWith( optName, "-" ) ) |
| 4276 | arg.shortNames.push_back( optName.substr( 1 ) ); |
| 4277 | else |
| 4278 | throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" ); |
| 4279 | } |
| 4280 | friend void setPositionalArg( Arg& arg, int position ) |
| 4281 | { |
nothing calls this directly
no outgoing calls
no test coverage detected