aboutsummaryrefslogtreecommitdiff
path: root/bpkg/types-parsers.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-01-11 21:39:15 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-01-12 13:07:30 +0300
commitdb4a9915b25ab682762eb73d65aab44e6bddcc1f (patch)
treea4be1c133feb07948dff504abb5e4f9cf9defe84 /bpkg/types-parsers.cxx
parent01c179eed3fcfccc7cdd262742935177dfcf5106 (diff)
Add --git-capabilities common option
Diffstat (limited to 'bpkg/types-parsers.cxx')
-rw-r--r--bpkg/types-parsers.cxx79
1 files changed, 79 insertions, 0 deletions
diff --git a/bpkg/types-parsers.cxx b/bpkg/types-parsers.cxx
index e27f050..f23751d 100644
--- a/bpkg/types-parsers.cxx
+++ b/bpkg/types-parsers.cxx
@@ -3,6 +3,8 @@
#include <bpkg/types-parsers.hxx>
+#include <libbpkg/manifest.hxx>
+
namespace bpkg
{
namespace cli
@@ -141,6 +143,83 @@ namespace bpkg
throw invalid_value (o, v);
}
+ void parser<git_protocol_capabilities>::
+ parse (git_protocol_capabilities& x, bool& xs, scanner& s)
+ {
+ xs = true;
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ const string v (s.next ());
+ if (v == "dumb")
+ x = git_protocol_capabilities::dumb;
+ else if (v == "smart")
+ x = git_protocol_capabilities::smart;
+ else if (v == "unadv")
+ x = git_protocol_capabilities::unadv;
+ else
+ throw invalid_value (o, v);
+ }
+
+ void parser<git_capabilities_map>::
+ parse (git_capabilities_map& x, bool& xs, scanner& s)
+ {
+ xs = true;
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ string v (s.next ());
+ size_t p (v.rfind ('='));
+
+ if (p == string::npos)
+ throw invalid_value (o, v);
+
+ string k (v, 0, p);
+
+ // Verify that the key is a valid remote git repository URL prefix.
+ //
+ try
+ {
+ repository_url u (k);
+
+ if (u.scheme == repository_protocol::file)
+ throw invalid_value (o, k, "local repository location");
+ }
+ catch (const invalid_argument& e)
+ {
+ throw invalid_value (o, k, e.what ());
+ }
+
+ // Parse the protocol capabilities value.
+ //
+ int ac (2);
+ char* av[] = {const_cast<char*> (o),
+ const_cast<char*> (v.c_str () + p + 1)};
+
+ argv_scanner vs (0, ac, av);
+
+ bool dummy;
+ parser<git_protocol_capabilities>::parse (x[k], dummy, vs);
+ }
+
+ void parser<git_capabilities_map>::
+ merge (git_capabilities_map& b, const git_capabilities_map& a)
+ {
+ for (const auto& o: a)
+ {
+ auto i (b.find (o.first));
+
+ if (i != b.end ())
+ i->second = o.second;
+ else
+ b.emplace (o.first, o.second);
+ }
+ }
+
void parser<stdout_format>::
parse (stdout_format& x, bool& xs, scanner& s)
{