aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-25 10:07:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-25 10:07:31 +0200
commite2b8f68fcae70fca5971167613916a1aa9480817 (patch)
tree3e4b63695de7855d71082aa1abd090e10825de2a
parent234428e21adde0ddf60f9665edad3dcfb9fd2584 (diff)
Document new command, use --vcs|-s instead of --no-git
-rw-r--r--bdep/new-parsers.cxx29
-rw-r--r--bdep/new-parsers.hxx7
-rw-r--r--bdep/new-types.hxx30
-rw-r--r--bdep/new.cli108
-rw-r--r--bdep/new.cxx20
5 files changed, 166 insertions, 28 deletions
diff --git a/bdep/new-parsers.cxx b/bdep/new-parsers.cxx
index d5b8e6e..effa2a7 100644
--- a/bdep/new-parsers.cxx
+++ b/bdep/new-parsers.cxx
@@ -12,6 +12,7 @@ namespace bdep
{
using type = cmd_new_type;
using lang = cmd_new_lang;
+ using vcs = cmd_new_vcs;
// Parse comma-separated list of of options starting from the first comma
// at pos.
@@ -110,5 +111,33 @@ namespace bdep
xs = true;
}
+
+ void parser<vcs>::
+ parse (vcs& r, bool& xs, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ string v (s.next ());
+ size_t i (v.find (','));
+ string l (v, 0, i);
+
+ if (l == "git")
+ {
+ r.vcs = vcs::git;
+ r.git_opt = parse_options<cmd_new_git_options> (o, v, i);
+ }
+ else if (l == "none")
+ {
+ r.vcs = vcs::none;
+ r.none_opt = parse_options<cmd_new_none_options> (o, v, i);
+ }
+ else
+ throw invalid_value (o, l);
+
+ xs = true;
+ }
}
}
diff --git a/bdep/new-parsers.hxx b/bdep/new-parsers.hxx
index c496314..d50dc09 100644
--- a/bdep/new-parsers.hxx
+++ b/bdep/new-parsers.hxx
@@ -32,6 +32,13 @@ namespace bdep
static void
parse (cmd_new_lang&, bool&, scanner&);
};
+
+ template <>
+ struct parser<cmd_new_vcs>
+ {
+ static void
+ parse (cmd_new_vcs&, bool&, scanner&);
+ };
}
}
diff --git a/bdep/new-types.hxx b/bdep/new-types.hxx
index b7161cd..616b87e 100644
--- a/bdep/new-types.hxx
+++ b/bdep/new-types.hxx
@@ -24,7 +24,7 @@ namespace bdep
typename BARE = cmd_new_bare_options>
struct cmd_new_type_template
{
- enum type_type {exe = 0, lib, bare} type; // Note: used as index.
+ enum type_type {exe, lib, bare} type;
operator type_type () const {return type;}
@@ -66,7 +66,7 @@ namespace bdep
typename CXX = cmd_new_cxx_options>
struct cmd_new_lang_template
{
- enum lang_type {c = 0, cxx} lang; // Note: used as index.
+ enum lang_type {c, cxx} lang;
operator lang_type () const {return lang;}
@@ -82,6 +82,32 @@ namespace bdep
};
using cmd_new_lang = cmd_new_lang_template<>;
+
+ // --vcs
+ //
+ class cmd_new_git_options;
+ class cmd_new_none_options;
+
+ template <typename GIT = cmd_new_git_options,
+ typename NONE = cmd_new_none_options>
+ struct cmd_new_vcs_template
+ {
+ enum vcs_type {git, none} vcs;
+
+ operator vcs_type () const {return vcs;}
+
+ union
+ {
+ GIT git_opt;
+ NONE none_opt;
+ };
+
+ // Default is git with no options.
+ //
+ cmd_new_vcs_template (): vcs (git) {git_opt = GIT ();}
+ };
+
+ using cmd_new_vcs = cmd_new_vcs_template<>;
}
#endif // BDEP_NEW_TYPES_HXX
diff --git a/bdep/new.cli b/bdep/new.cli
index 08eedc1..377dbec 100644
--- a/bdep/new.cli
+++ b/bdep/new.cli
@@ -15,6 +15,7 @@ namespace bdep
"<options> <spec> <name>
<type> <type-opt>
<lang> <lang-opt>
+ <vcs> <vcs-opt>
<cfg-name> <cfg-dir>
<cfg-args> <option> <module> <cfg-var>",
@@ -25,31 +26,86 @@ namespace bdep
\b{bdep new} [<options>] \b{--config-create|-C} <cfg-dir> [\b{@}<cfg-name>] <spec> <name>\n
\ \ \ \ \ \ \ \ \ [<cfg-args>]}
- \c{<spec> = [<type>] [<lang>]\n
- <type> = \b{--type}|\b{-t} (\b{exe}|\b{lib}|\b{bare})[\b{,}<type-opt>...]\n
- <lang> = \b{--lang}|\b{-l} (\b{c}|\b{c++})[\b{,}<lang-opt>...]\n
+ \c{<spec> \ \ \ \ = [<type>] [<lang>] [<vcs>]\n
+ <type> \ \ \ \ = \b{--type}|\b{-t} (\b{exe}|\b{lib}|\b{bare})[\b{,}<type-opt>...]\n
+ <lang> \ \ \ \ = \b{--lang}|\b{-l} (\b{c}|\b{c++})[\b{,}<lang-opt>...]\n
+ <vcs> \ \ \ \ \ = \b{--vcs}|\b{-s} \ (\b{git}|\b{none})[\b{,}<vcs-opt>...]\n
<cfg-args> = (<option> | <module> | <cfg-var>)...}
\h|DESCRIPTION|
- The \cb{new} command...
+ The \cb{new} command creates and initializes a new \cb{build2} project.
+ All three forms first create according to <spec> a new \cb{build2}
+ project called <name> in the <name> subdirectory of the current working
+ directory.
+
+ The first form then, unless the \cb{--no-init} option is specified,
+ initializes an empty project database as if by executing the
+ \l{bdep-init(1)} command with the \cb{--empty} option. Similarly, the
+ second and third forms add an existing or create new build configuration
+ and then initialize the project in that configuraton as if by executing
+ the \l{bdep-init(1)} command with the \cb{--config-add} or
+ \cb{--config-create} option, respectively.
+
+ The project parameters such as type (executable, library, etc), language,
+ and version control system can be customized as described next. Some of
+ the parameters also support parameter-specific options (such as the file
+ extensions to use in a C++ project) that can be specified after the
+ parameter value.
+
+ The project type can be specified with the \c{\b{--type}|\b{-t}} option.
+ Valid values for this option and their semantics are described next. If
+ unspecified, an executable project is created by default.
- The first form, unless the \cb{--no-init} is specified, initializes
- an empty configuration set, as if by performing \cb{init --empty}.
+ \dl|
+
+ \li|\cb{exe}
+
+ A project that builds a sample executable.|
+
+ \li|\cb{lib}
+
+ A project that builds a sample library.|
+
+ \li|\cb{bare}
- Recognized \cb{c++} language options:
+ A project without any source code.||
+
+ The project language can be specified with the \c{\b{--lang}|\b{-l}}
+ option. Valid values for this option and their semantics are described
+ next. If unspecified, a C++ project is created by default.
\dl|
- \li|\cb{cxx}
+ \li|\cb{c}
+
+ A C project.|
+
+ \li|\cb{c++}
- Use the \cb{.cxx}, \cb{.hxx}, \cb{.ixx}, \cb{.txx}, and \cb{.mxx}
- source file extensions (default).|
+ A C++ project. Recognized language options:
- \li|\cb{cpp}
+ \cb{cxx} \- Use the \cb{.cxx}, \cb{.hxx}, \cb{.ixx}, \cb{.txx}, and
+ \cb{.mxx} source file extensions (default).
- Use the \cb{.cpp}, \cb{.hpp}, \cb{.ipp}, \cb{.tpp}, and \cb{.mpp}
- source file extensions.||
+ \cb{cpp} \- Use the \cb{.cpp}, \cb{.hpp}, \cb{.ipp}, \cb{.tpp}, and
+ \cb{.mpp} source file extensions.||
+
+ The project version control system can be specified with the
+ \c{\b{--vcs}|\b{-s}} option. Valid values for this option and their
+ semantics are described next. If unspecified, \cb{git} is assumed by
+ default.
+
+ \dl|
+
+ \li|\cb{git}
+
+ Initialize a \cb{git(1)} repository inside the project and generate
+ \cb{.gitignore} files.|
+
+ \li|\cb{none}
+
+ Don't initialize a version control system inside the project.||
"
}
@@ -79,6 +135,16 @@ namespace bdep
bool cxx;
};
+ // --vcs options
+ //
+ class cmd_new_git_options
+ {
+ };
+
+ class cmd_new_none_options
+ {
+ };
+
class cmd_new_options: configuration_name_options
{
"\h|NEW OPTIONS|"
@@ -104,22 +170,24 @@ namespace bdep
{
"<type>[,<opt>...]",
"Specify project type and options. Valid values for <type> are \cb{exe}
- (executable project, default) \cb{lib} (library project), and \cb{bare}
- (bare project without any source code). Valid values for <opt> are
- type-specific."
+ (executable project, default), \cb{lib} (library project), and
+ \cb{bare} (bare project without any source code). Valid values for
+ <opt> are type-specific."
}
cmd_new_lang --lang|-l
{
"<lang>[,<opt>...]",
- "Specify language type and options. Valid values for <lang> are \cb{c},
+ "Specify language type and options. Valid values for <lang> are \cb{c}
and \cb{c++} (default). Valid values for <opt> are language-specific."
}
- bool --no-git
+ cmd_new_vcs --vcs|-s
{
- "Don't initialize a \cb{git(1)} repository inside the project nor
- generate any \cb{.gitignore} files."
+ "<vcs>[,<opt>...]",
+ "Specify version control system and options. Valid values for <vcs> are
+ \cb{git} (default) and \cb{none}. Valid values for <opt> are
+ system-specific."
}
bool --default
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 9ab63f4..3e3b3b8 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -16,6 +16,7 @@ namespace bdep
{
using type = cmd_new_type;
using lang = cmd_new_lang;
+ using vcs = cmd_new_vcs;
int
cmd_new (const cmd_new_options& o, cli::scanner& args)
@@ -68,6 +69,10 @@ namespace bdep
}
}
+ // Validate type options.
+ //
+ const vcs& s (o.vcs ());
+
// Validate argument.
//
string n (args.more () ? args.next () : "");
@@ -90,11 +95,14 @@ namespace bdep
else if (!empty (prj))
fail << "directory " << prj << " already exists";
- // Initialize the git repository. Do it before writing anything ourselves
- // in case it fails.
+ // Initialize the version control system. Do it before writing anything
+ // ourselves in case it fails.
//
- if (!o.no_git ())
- run ("git", "init", "-q", prj);
+ switch (s)
+ {
+ case vcs::git: run ("git", "init", "-q", prj); break;
+ case vcs::none: break;
+ }
path f; // File currently being written.
try
@@ -186,7 +194,7 @@ namespace bdep
// build/.gitignore
//
- if (!o.no_git ())
+ if (s == vcs::git)
{
os.open (f = bd / ".gitignore");
os << "config.build" << endl
@@ -202,7 +210,7 @@ namespace bdep
// .gitignore
//
- if (!o.no_git ())
+ if (s == vcs::git)
{
// Use POSIX directory separators here.
//