aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-18 07:50:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-18 07:50:38 +0200
commit9accdefc33940d713828195313ca1a0eb0de030f (patch)
tree22f1e84a97d3ba353788d5ec30c20ea4c6d43670
parentcae11509203061e894e6310c35ea50ae818af3a7 (diff)
Generalize pkg_update() to pkg_command() to be used for clean, test, etc
-rw-r--r--bpkg/buildfile51
-rw-r--r--bpkg/pkg-command21
-rw-r--r--bpkg/pkg-command.cxx (renamed from bpkg/pkg-update.cxx)20
-rw-r--r--bpkg/pkg-common-options.cli18
-rw-r--r--bpkg/pkg-configure-options.cli10
-rw-r--r--bpkg/pkg-disfigure-options.cli10
-rw-r--r--bpkg/pkg-fetch-options.cli11
-rw-r--r--bpkg/pkg-purge-options.cli11
-rw-r--r--bpkg/pkg-status-options.cli10
-rw-r--r--bpkg/pkg-unpack-options.cli11
-rw-r--r--bpkg/pkg-update8
-rw-r--r--bpkg/pkg-update-options.cli10
12 files changed, 104 insertions, 87 deletions
diff --git a/bpkg/buildfile b/bpkg/buildfile
index e8f156e..2e840ca 100644
--- a/bpkg/buildfile
+++ b/bpkg/buildfile
@@ -13,6 +13,8 @@ exe{bpkg}: cxx{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} \
@@ -20,34 +22,49 @@ exe{bpkg}: cxx{package package-odb database diagnostics utility} \
cxx{pkg-purge} cli.cxx{pkg-purge-options} \
cxx{pkg-configure} cli.cxx{pkg-configure-options} \
cxx{pkg-disfigure} cli.cxx{pkg-disfigure-options} \
- cxx{pkg-update} cli.cxx{pkg-update-options} \
+ cli.cxx{pkg-update-options} \
cxx{cfg-create} cli.cxx{cfg-create-options} \
cxx{rep-create} cli.cxx{rep-create-options} \
$libs
+# Option length must be the same to get commands/topics/options aligned.
+#
cli.options += -I $src_root --include-with-brackets --include-prefix bpkg \
--guard-prefix BPKG --cxx-prologue "#include <bpkg/types-parsers>" \
--cli-namespace bpkg::cli --generate-file-scanner --generate-specifier \
---generate-parse --long-usage --exclude-base
+--generate-parse --long-usage --option-length 22
-# Option length must be the same to get commands/topics/options lists
-# aligned in the general help.
-#
cli.cxx{common-options}: cli{common-options}
-cli.cxx{common-options}: cli.options += --option-length 22 --short-usage
+cli.cxx{common-options}: cli.options += --short-usage
cli.cxx{bpkg-options}: cli{bpkg-options}
-cli.cxx{bpkg-options}: cli.options += --option-length 22 --short-usage
+cli.cxx{bpkg-options}: cli.options += --short-usage
cli.cxx{help-options}: cli{help-options}
+cli.cxx{help-options}: cli.options += --exclude-base
+
+# pkg-*
+#
+cli.cxx{pkg-common-options}: cli{pkg-common-options}
+cli.cxx{pkg-common-options}: cli.options += --exclude-base
+
+cli.cxx{pkg-status-options}: cli{pkg-status-options}
+cli.cxx{pkg-fetch-options}: cli{pkg-fetch-options}
+cli.cxx{pkg-unpack-options}: cli{pkg-unpack-options}
+cli.cxx{pkg-purge-options}: cli{pkg-purge-options}
+cli.cxx{pkg-configure-options}: cli{pkg-configure-options}
+cli.cxx{pkg-disfigure-options}: cli{pkg-disfigure-options}
+cli.cxx{pkg-update-options}: cli{pkg-update-options}
-cli.cxx{pkg-verify-options}: cli{pkg-verify-options}
-cli.cxx{pkg-status-options}: cli{pkg-status-options}
-cli.cxx{pkg-fetch-options}: cli{pkg-fetch-options}
-cli.cxx{pkg-unpack-options}: cli{pkg-unpack-options}
-cli.cxx{pkg-purge-options}: cli{pkg-purge-options}
-cli.cxx{pkg-configure-options}: cli{pkg-configure-options}
-cli.cxx{pkg-disfigure-options}: cli{pkg-disfigure-options}
-cli.cxx{pkg-update-options}: cli{pkg-update-options}
-cli.cxx{cfg-create-options}: cli{cfg-create-options}
-cli.cxx{rep-create-options}: cli{rep-create-options}
+cli.cxx{pkg-verify-options}: cli{pkg-verify-options}
+cli.cxx{pkg-verify-options}: cli.options += --exclude-base
+
+# cfg-*
+#
+cli.cxx{cfg-create-options}: cli{cfg-create-options}
+cli.cxx{cfg-create-options}: cli.options += --exclude-base
+
+# rep-*
+#
+cli.cxx{rep-create-options}: cli{rep-create-options}
+cli.cxx{rep-create-options}: cli.options += --exclude-base
diff --git a/bpkg/pkg-command b/bpkg/pkg-command
new file mode 100644
index 0000000..225a112
--- /dev/null
+++ b/bpkg/pkg-command
@@ -0,0 +1,21 @@
+// file : bpkg/pkg-command -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BPKG_PKG_COMMAND
+#define BPKG_PKG_COMMAND
+
+#include <bpkg/types>
+#include <bpkg/pkg-common-options>
+
+namespace bpkg
+{
+ // Common pkg-{update,clean,test,install,...} implementation.
+ //
+ void
+ pkg_command (const string& cmd, // Without the 'pkg-' prefix.
+ const pkg_common_options&,
+ cli::scanner& args);
+}
+
+#endif // BPKG_PKG_COMMAND
diff --git a/bpkg/pkg-update.cxx b/bpkg/pkg-command.cxx
index 015a628..b4e2893 100644
--- a/bpkg/pkg-update.cxx
+++ b/bpkg/pkg-command.cxx
@@ -1,8 +1,8 @@
-// file : bpkg/pkg-update.cxx -*- C++ -*-
+// file : bpkg/pkg-command.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#include <bpkg/pkg-update>
+#include <bpkg/pkg-command>
#include <bpkg/types>
#include <bpkg/package>
@@ -17,16 +17,19 @@ using namespace butl;
namespace bpkg
{
void
- pkg_update (const pkg_update_options& o, cli::scanner& args)
+ pkg_command (const string& cmd,
+ const pkg_common_options& o,
+ cli::scanner& args)
{
- tracer trace ("pkg_update");
+ tracer trace ("pkg_command");
+ level4 ([&]{trace << "command: " << cmd;});
const dir_path& c (o.directory ());
level4 ([&]{trace << "configuration: " << c;});
if (!args.more ())
fail << "package name argument expected" <<
- info << "run 'bpkg help pkg-update' for more information";
+ info << "run 'bpkg help pkg-" << cmd << "' for more information";
string n (args.next ());
@@ -51,14 +54,13 @@ namespace bpkg
// Form the buildspec.
//
- string bspec ("update(" + out_root.string () + "/)");
+ string bspec (cmd + "(" + out_root.string () + "/)");
level4 ([&]{trace << "buildspec: " << bspec;});
- // Update.
- //
run_b (bspec);
if (verb)
- text << "updated " << p->name << " " << p->version;
+ text << cmd << (cmd.back () != 'e' ? "ed " : "d ")
+ << p->name << " " << p->version;
}
}
diff --git a/bpkg/pkg-common-options.cli b/bpkg/pkg-common-options.cli
new file mode 100644
index 0000000..d7097ff
--- /dev/null
+++ b/bpkg/pkg-common-options.cli
@@ -0,0 +1,18 @@
+// file : bpkg/pkg-common-options.cli
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+include <bpkg/common-options.cli>;
+
+namespace bpkg
+{
+ class pkg_common_options: common_options
+ {
+ dir_path --directory|-d (".")
+ {
+ "<dir>",
+ "Assume configuration is in <dir> rather than in the current working
+ directory."
+ };
+ };
+}
diff --git a/bpkg/pkg-configure-options.cli b/bpkg/pkg-configure-options.cli
index d1850c6..85e4fa9 100644
--- a/bpkg/pkg-configure-options.cli
+++ b/bpkg/pkg-configure-options.cli
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-include <bpkg/common-options.cli>;
+include <bpkg/pkg-common-options.cli>;
/*
"\section=1"
@@ -24,13 +24,7 @@ after the package name."
namespace bpkg
{
- class pkg_configure_options: common_options
+ class pkg_configure_options: pkg_common_options
{
- dir_path --directory|-d (".")
- {
- "<dir>",
- "Assume configuration is in <dir> rather than in the current working
- directory."
- };
};
}
diff --git a/bpkg/pkg-disfigure-options.cli b/bpkg/pkg-disfigure-options.cli
index 7e451e8..9ffe20b 100644
--- a/bpkg/pkg-disfigure-options.cli
+++ b/bpkg/pkg-disfigure-options.cli
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-include <bpkg/common-options.cli>;
+include <bpkg/pkg-common-options.cli>;
/*
"\section=1"
@@ -20,13 +20,7 @@ The \cb{pkg-disfigure} command disfigures the previously configured
namespace bpkg
{
- class pkg_disfigure_options: common_options
+ class pkg_disfigure_options: pkg_common_options
{
- dir_path --directory|-d (".")
- {
- "<dir>",
- "Assume configuration is in <dir> rather than in the current working
- directory."
- };
};
}
diff --git a/bpkg/pkg-fetch-options.cli b/bpkg/pkg-fetch-options.cli
index 0ad0531..54a2f50 100644
--- a/bpkg/pkg-fetch-options.cli
+++ b/bpkg/pkg-fetch-options.cli
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-include <bpkg/common-options.cli>;
+include <bpkg/pkg-common-options.cli>;
/*
"\section=1"
@@ -27,15 +27,8 @@ attempt to remove the archive when the package is purged with the
namespace bpkg
{
- class pkg_fetch_options: common_options
+ class pkg_fetch_options: pkg_common_options
{
- dir_path --directory|-d (".")
- {
- "<dir>",
- "Assume configuration is in <dir> rather than in the current working
- directory."
- };
-
bool --existing|-e
{
"Treat the argument as an existing package archive path rather than
diff --git a/bpkg/pkg-purge-options.cli b/bpkg/pkg-purge-options.cli
index 8d7d61b..2341b74 100644
--- a/bpkg/pkg-purge-options.cli
+++ b/bpkg/pkg-purge-options.cli
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-include <bpkg/common-options.cli>;
+include <bpkg/pkg-common-options.cli>;
/*
"\section=1"
@@ -26,15 +26,8 @@ this mode)."
namespace bpkg
{
- class pkg_purge_options: common_options
+ class pkg_purge_options: pkg_common_options
{
- dir_path --directory|-d (".")
- {
- "<dir>",
- "Assume configuration is in <dir> rather than in the current working
- directory."
- };
-
bool --keep|-k
{
"Keep the package archive. Note that in this mode the package is
diff --git a/bpkg/pkg-status-options.cli b/bpkg/pkg-status-options.cli
index 700f5fa..b094e34 100644
--- a/bpkg/pkg-status-options.cli
+++ b/bpkg/pkg-status-options.cli
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-include <bpkg/common-options.cli>;
+include <bpkg/pkg-common-options.cli>;
/*
"\section=1"
@@ -22,13 +22,7 @@ Note that the status is written to \cb{STDOUT}, not \cb{STDERR}.
namespace bpkg
{
- class pkg_status_options: common_options
+ class pkg_status_options: pkg_common_options
{
- dir_path --directory|-d (".")
- {
- "<dir>",
- "Assume configuration is in <dir> rather than in the current working
- directory."
- };
};
}
diff --git a/bpkg/pkg-unpack-options.cli b/bpkg/pkg-unpack-options.cli
index 7ffcc62..06fda13 100644
--- a/bpkg/pkg-unpack-options.cli
+++ b/bpkg/pkg-unpack-options.cli
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-include <bpkg/common-options.cli>;
+include <bpkg/pkg-common-options.cli>;
/*
"\section=1"
@@ -27,15 +27,8 @@ command."
namespace bpkg
{
- class pkg_unpack_options: common_options
+ class pkg_unpack_options: pkg_common_options
{
- dir_path --directory|-d (".")
- {
- "<dir>",
- "Assume configuration is in <dir> rather than in the current working
- directory."
- };
-
bool --existing|-e
{
"Treat the argument as an existing package directory path rather than
diff --git a/bpkg/pkg-update b/bpkg/pkg-update
index 0ff4b0d..4c89e66 100644
--- a/bpkg/pkg-update
+++ b/bpkg/pkg-update
@@ -6,12 +6,16 @@
#define BPKG_PKG_UPDATE
#include <bpkg/types>
+#include <bpkg/pkg-command>
#include <bpkg/pkg-update-options>
namespace bpkg
{
- void
- pkg_update (const pkg_update_options&, cli::scanner& args);
+ inline void
+ pkg_update (const pkg_update_options& o, cli::scanner& args)
+ {
+ pkg_command ("update", o, args);
+ }
}
#endif // BPKG_PKG_UPDATE
diff --git a/bpkg/pkg-update-options.cli b/bpkg/pkg-update-options.cli
index e9fbbb2..d259ce3 100644
--- a/bpkg/pkg-update-options.cli
+++ b/bpkg/pkg-update-options.cli
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-include <bpkg/common-options.cli>;
+include <bpkg/pkg-common-options.cli>;
/*
"\section=1"
@@ -21,13 +21,7 @@ do much more than run (\cb{b update})."
namespace bpkg
{
- class pkg_update_options: common_options
+ class pkg_update_options: pkg_common_options
{
- dir_path --directory|-d (".")
- {
- "<dir>",
- "Assume configuration is in <dir> rather than in the current working
- directory."
- };
};
}