// file : bdep/types-parsers.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file #include #include // bdep::cli namespace namespace bdep { namespace cli { void parser:: parse (url& x, bool& xs, scanner& s) { const char* o (s.next ()); if (!s.more ()) throw missing_value (o); const char* v (s.next ()); try { x = url (v); } catch (const invalid_argument& e) { throw invalid_value (o, v, e.what ()); } xs = true; } template static void parse_path (T& x, scanner& s) { const char* o (s.next ()); if (!s.more ()) throw missing_value (o); const char* v (s.next ()); try { x = T (v); if (x.empty ()) throw invalid_value (o, v); } catch (const invalid_path&) { throw invalid_value (o, v); } } void parser:: parse (path& x, bool& xs, scanner& s) { xs = true; parse_path (x, s); } void parser:: parse (dir_path& x, bool& xs, scanner& s) { xs = true; parse_path (x, s); } void parser:: parse (stdout_format& r, bool& xs, scanner& s) { const char* o (s.next ()); if (!s.more ()) throw missing_value (o); string v (s.next ()); if (v == "lines") r = stdout_format::lines; else if (v == "json") r = stdout_format::json; else throw invalid_value (o, v); xs = true; } } }