aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/buildfile42
-rw-r--r--bpkg/manifest-utility26
-rw-r--r--bpkg/manifest-utility.cxx44
-rw-r--r--bpkg/pkg-fetch.cxx17
-rw-r--r--bpkg/pkg-status.cxx13
-rw-r--r--bpkg/rep-add.cxx19
-rw-r--r--bpkg/rep-info.cxx20
7 files changed, 99 insertions, 82 deletions
diff --git a/bpkg/buildfile b/bpkg/buildfile
index 919f5fe..54226f3 100644
--- a/bpkg/buildfile
+++ b/bpkg/buildfile
@@ -9,27 +9,27 @@ import libs += libbutl%lib{butl}
import libs += libodb%lib{odb}
import libs += libodb-sqlite%lib{odb-sqlite}
-exe{bpkg}: cxx{fetch package package-odb database diagnostics \
- utility} \
- cli.cxx{common-options} cxx{types-parsers} \
- cxx{bpkg} cli.cxx{bpkg-options} \
- cxx{help} cli.cxx{help-options} \
- cli.cxx{pkg-common-options} \
- cxx{pkg-command} \
- cxx{pkg-verify} cli.cxx{pkg-verify-options} \
- cxx{pkg-status} cli.cxx{pkg-status-options} \
- cxx{pkg-fetch} cli.cxx{pkg-fetch-options} \
- cxx{pkg-unpack} cli.cxx{pkg-unpack-options} \
- cxx{pkg-purge} cli.cxx{pkg-purge-options} \
- cxx{pkg-configure} cli.cxx{pkg-configure-options} \
- cxx{pkg-disfigure} cli.cxx{pkg-disfigure-options} \
- cli.cxx{pkg-update-options} \
- cli.cxx{pkg-clean-options} \
- cxx{cfg-create} cli.cxx{cfg-create-options} \
- cxx{rep-add} cli.cxx{rep-add-options} \
- cxx{rep-fetch} cli.cxx{rep-fetch-options} \
- cxx{rep-info} cli.cxx{rep-info-options} \
- cxx{rep-create} cli.cxx{rep-create-options} \
+exe{bpkg}: cxx{fetch package package-odb manifest-utility database \
+ diagnostics utility} \
+ cli.cxx{common-options} cxx{types-parsers} \
+ cxx{bpkg} cli.cxx{bpkg-options} \
+ cxx{help} cli.cxx{help-options} \
+ cli.cxx{pkg-common-options} \
+ cxx{pkg-command} \
+ cxx{pkg-verify} cli.cxx{pkg-verify-options} \
+ cxx{pkg-status} cli.cxx{pkg-status-options} \
+ cxx{pkg-fetch} cli.cxx{pkg-fetch-options} \
+ cxx{pkg-unpack} cli.cxx{pkg-unpack-options} \
+ cxx{pkg-purge} cli.cxx{pkg-purge-options} \
+ cxx{pkg-configure} cli.cxx{pkg-configure-options} \
+ cxx{pkg-disfigure} cli.cxx{pkg-disfigure-options} \
+ cli.cxx{pkg-update-options} \
+ cli.cxx{pkg-clean-options} \
+ cxx{cfg-create} cli.cxx{cfg-create-options} \
+ cxx{rep-add} cli.cxx{rep-add-options} \
+ cxx{rep-fetch} cli.cxx{rep-fetch-options} \
+ cxx{rep-info} cli.cxx{rep-info-options} \
+ cxx{rep-create} cli.cxx{rep-create-options} \
$libs
# Option length must be the same to get commands/topics/options aligned.
diff --git a/bpkg/manifest-utility b/bpkg/manifest-utility
new file mode 100644
index 0000000..f9766c7
--- /dev/null
+++ b/bpkg/manifest-utility
@@ -0,0 +1,26 @@
+// file : bpkg/manifest-utility -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BPKG_MANIFEST_UTILITY
+#define BPKG_MANIFEST_UTILITY
+
+#include <bpkg/manifest>
+
+#include <bpkg/types>
+#include <bpkg/utility>
+
+namespace bpkg
+{
+ version
+ parse_version (const char*);
+
+ // First use the passed location as is. If the result is relative,
+ // then assume this is a relative path to the repository directory
+ // and complete it based on the current working directory.
+ //
+ repository_location
+ parse_location (const char*);
+}
+
+#endif // BPKG_MANIFEST_UTILITY
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 ();
+ }
+}
diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx
index bfa6e54..1406d8d 100644
--- a/bpkg/pkg-fetch.cxx
+++ b/bpkg/pkg-fetch.cxx
@@ -13,6 +13,7 @@
#include <bpkg/utility>
#include <bpkg/database>
#include <bpkg/diagnostics>
+#include <bpkg/manifest-utility>
#include <bpkg/pkg-verify>
@@ -61,21 +62,7 @@ namespace bpkg
fail << "package version argument expected" <<
info << "run 'bpkg help pkg-fetch' for more information";
- //@@ Same code as in pkg-status. Similar problem to repo_location;
- // need a place for such utilities.
- //
- version v;
- {
- const char* s (args.next ());
- try
- {
- v = version (s);
- }
- catch (const invalid_argument& e)
- {
- fail << "invalid package version '" << s << "': " << e.what ();
- }
- }
+ version v (parse_version (args.next ()));
if (db.query_value<repository_count> () == 0)
fail << "configuration " << c << " has no repositories" <<
diff --git a/bpkg/pkg-status.cxx b/bpkg/pkg-status.cxx
index 8daf781..c75019e 100644
--- a/bpkg/pkg-status.cxx
+++ b/bpkg/pkg-status.cxx
@@ -12,6 +12,7 @@
#include <bpkg/utility>
#include <bpkg/database>
#include <bpkg/diagnostics>
+#include <bpkg/manifest-utility>
using namespace std;
using namespace butl;
@@ -34,17 +35,7 @@ namespace bpkg
version v;
if (args.more ())
- {
- const char* s (args.next ());
- try
- {
- v = version (s);
- }
- catch (const invalid_argument& e)
- {
- fail << "invalid package version '" << s << "': " << e.what ();
- }
- }
+ v = parse_version (args.next ());
database db (open (c, trace));
transaction t (db.begin ());
diff --git a/bpkg/rep-add.cxx b/bpkg/rep-add.cxx
index 924cd65..bed6b86 100644
--- a/bpkg/rep-add.cxx
+++ b/bpkg/rep-add.cxx
@@ -12,6 +12,7 @@
#include <bpkg/utility>
#include <bpkg/database>
#include <bpkg/diagnostics>
+#include <bpkg/manifest-utility>
using namespace std;
using namespace butl;
@@ -30,23 +31,7 @@ namespace bpkg
fail << "repository location argument expected" <<
info << "run 'bpkg help rep-add' for more information";
- // Figure out the repository location.
- //
- const char* arg (args.next ());
- repository_location rl;
- try
- {
- rl = repository_location (arg, repository_location ());
-
- if (rl.relative ()) // Throws if location is empty.
- rl = repository_location (
- dir_path (arg).complete ().normalize ().string ());
- }
- catch (const invalid_argument& e)
- {
- fail << "invalid repository location '" << arg << "': " << e.what ();
- }
-
+ repository_location rl (parse_location (args.next ()));
const string& rn (rl.canonical_name ());
// Create the new repository and add is as a complement to the root.
diff --git a/bpkg/rep-info.cxx b/bpkg/rep-info.cxx
index 64ac9b1..224866c 100644
--- a/bpkg/rep-info.cxx
+++ b/bpkg/rep-info.cxx
@@ -14,6 +14,7 @@
#include <bpkg/types>
#include <bpkg/utility>
#include <bpkg/diagnostics>
+#include <bpkg/manifest-utility>
using namespace std;
using namespace butl;
@@ -29,24 +30,7 @@ namespace bpkg
fail << "repository location argument expected" <<
info << "run 'bpkg help rep-info' for more information";
- // Figure out the repository location.
- //
- // @@ The same code as in rep-add, factor out.
- //
- const char* arg (args.next ());
- repository_location rl;
- try
- {
- rl = repository_location (arg, repository_location ());
-
- if (rl.relative ()) // Throws if location is empty.
- rl = repository_location (
- dir_path (arg).complete ().normalize ().string ());
- }
- catch (const invalid_argument& e)
- {
- fail << "invalid repository location '" << arg << "': " << e.what ();
- }
+ repository_location rl (parse_location (args.next ()));
// Fetch everything we will need before printing anything.
//