aboutsummaryrefslogtreecommitdiff
path: root/bpkg/manifest-utility.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-28 08:38:40 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-28 08:38:40 +0200
commit749cd532f72108b26a78cd2f0012e6abd72b3ce8 (patch)
treedf9f424dba608536cf77c3d188a53df89a4b6440 /bpkg/manifest-utility.cxx
parentc602595c08efae5ff1b05e0b8c7d4ab430f8f033 (diff)
Factory common code for version, repository location parsing
Diffstat (limited to 'bpkg/manifest-utility.cxx')
-rw-r--r--bpkg/manifest-utility.cxx44
1 files changed, 44 insertions, 0 deletions
diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx
new file mode 100644
index 0000000..76c1957
--- /dev/null
+++ b/bpkg/manifest-utility.cxx
@@ -0,0 +1,44 @@
+// file : bpkg/manifest-utility.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bpkg/manifest-utility>
+
+#include <stdexcept> // invalid_argument
+
+#include <bpkg/diagnostics>
+
+using namespace std;
+
+namespace bpkg
+{
+ version
+ parse_version (const char* s)
+ try
+ {
+ return version (s);
+ }
+ catch (const invalid_argument& e)
+ {
+ error << "invalid package version '" << s << "': " << e.what ();
+ throw failed ();
+ }
+
+ repository_location
+ parse_location (const char* s)
+ try
+ {
+ repository_location rl (s, repository_location ());
+
+ if (rl.relative ()) // Throws if the location is empty.
+ rl = repository_location (
+ dir_path (s).complete ().normalize ().string ());
+
+ return rl;
+ }
+ catch (const invalid_argument& e)
+ {
+ error << "invalid repository location '" << s << "': " << e.what ();
+ throw failed ();
+ }
+}