aboutsummaryrefslogtreecommitdiff
path: root/bdep/new.cli
blob: faf412d0b4415cf9cf1e9e1f7b09bd99a6d31a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
// file      : bdep/new.cli
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

include <bdep/project.cli>;
include <bdep/new-types.hxx>;

"\section=1"
"\name=bdep-new"
"\summary=create and initialize new project"

namespace bdep
{
  {
    "<options> <spec> <name>
     <type> <type-opt>
     <lang> <lang-opt>
     <vcs> <vcs-opt>
     <cfg-name> <cfg-dir>
     <prj-spec> <prj-dir>
     <cfg-args> <option> <module> <cfg-var>",

    "\h|SYNOPSIS|

     \c{\b{bdep new} [<options>] [\b{--no-init}] <spec> <name>\n
        \b{bdep new} [<options>] \b{--config-add|-A} <cfg-dir> [\b{@}<cfg-name>] <spec> <name>\n
        \b{bdep new} [<options>] \b{--config-create|-C} <cfg-dir> [\b{@}<cfg-name>] <spec> <name>\n
        \ \ \ \ \ \ \ \ \ [<cfg-args>]\n
        \b{bdep new} [<options>] \b{--package} [<prj-spec>] <spec> <name>\n
        \b{bdep new} [<options>] \b{--subdirectory} [<prj-spec>] <spec> <name>}

     \c{<spec> \ \ \ \ = [<type>] [<lang>] [<vcs>]\n
        <type> \ \ \ \ = \b{--type}|\b{-t} (\b{exe}|\b{lib}|\b{bare}|\b{empty})[\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
        <prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n
        <cfg-args> = (<option> | <module> | <cfg-var>)...}

     \h|DESCRIPTION|

     The \cb{new} command creates and initializes a new project (the first
     three forms), a new package in an already existing project (the
     \cb{--package} form), or a new source subdirectory in an already existing
     project/package (the \cb{--subdirectory} form). All the forms except
     \cb{--subdirectory} first create according to <spec> a new \cb{build2}
     project/package called <name> in the <name> subdirectory of the current
     working directory (unless overridden with \c{\b{--output-dir}|\b{-o}}).
     See \l{bpkg#package-name Package Name} for details on project/package
     names.

     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. For example:

     \
     $ bdep new -t exe -l c++ hello
     \

     Similarly, the second and third forms add an existing or create new build
     configuration and then initialize the project in that configuration as if
     by executing the \l{bdep-init(1)} command with the \cb{--config-add} or
     \cb{--config-create} option, respectively. For example:

     \
     $ bdep new -t exe -l c++ -C @gcc hello cc config.cxx=g++
     \

     The \cb{--package} form adds the new package to the
     \cb{packages.manifest} file creating it if necessary. If no project
     directory is explicitly specified with \c{\b{--directory}|\b{-d}}, then
     the current working directory is assumed. Note that nested packages are
     not allowed. For example:

     \
     $ bdep new -t empty hello
     $ cd hello

     $ bdep new --package -t lib -l c++ libhello
     $ bdep new --package -t exe -l c++ hello

     $ bdep init -C @gcc cc config.cxx=g++
     \

     After executing these commands the \cb{hello} project will contain two
     packages, \cb{libhello} and \cb{hello}.

     The \cb{--subdirectory} form operates \i{as-if} by first creating
     according to <spec> a temporary project called <name> and then copying
     its source subdirectory (\c{\i{name}\b{/}\i{name}\b{/}}) over to the
     current working directory (unless overridden with
     \c{\b{--output-dir}|\b{-o}}). If no project/package directory is
     explicitly specified with \c{\b{--directory}|\b{-d}}, then the current
     working directory is assumed. For example:

     \
     $ bdep new -t bare hello
     $ cd hello

     $ bdep new --subdirectory -t lib -l c++ libhello
     $ bdep new --subdirectory -t exe -l c++ hello

     $ bdep init -C @gcc cc config.cxx=g++
     \

     After executing these commands the \cb{hello} project will contain two
     source subdirectories, \cb{libhello/} and \cb{hello/}.

     The project parameters such as type (executable, library, etc), language,
     and version control system can be customized as described next. Some of
     these parameters also support parameter-specific sub-options (such as the
     file extensions to use in a C++ project) that can be specified with a
     comma 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.

     \dl|

     \li|\cb{exe}

         A project that builds a sample executable. Recognized
         executable project sub-options:|

     \li|\n\ \ \ \cb{no-tests}

         Don't add support for functional/integration testing.|

     \li|\n\ \ \ \cb{unit-tests}

         Add support for unit testing.|

     \li|\n\ \ \ \c{\b{license=}\i{name}}|

     \li|\ \ \ \cb{no-readme}|

     \li|\ \ \ \cb{alt-naming}

         See \cb{common} sub-options below.||

     \dl|

     \li|\cb{lib}

         A project that builds a sample library. Recognized library
         project sub-options:|

     \li|\n\ \ \ \cb{no-tests}

         Don't add support for functional/integration testing.|

     \li|\n\ \ \ \cb{unit-tests}

         Add support for unit testing.|

     \li|\n\ \ \ \cb{no-version}

         Don't add support for generating the version header.|

     \li|\n\ \ \ \c{\b{license=}\i{name}}|

     \li|\ \ \ \cb{no-readme}|

     \li|\ \ \ \cb{alt-naming}

         See \cb{common} sub-options below.||

     \dl|

     \li|\cb{bare}

         A project without any source code that can be filled later
         (see \cb{--subdirectory}). Recognized bare project sub-options:|

     \li|\n\ \ \ \cb{no-tests}

         Don't add support for testing.|

     \li|\n\ \ \ \c{\b{license=}\i{name}}|

     \li|\ \ \ \cb{no-readme}|

     \li|\ \ \ \cb{alt-naming}

         See \cb{common} sub-options below.||

     \dl|

     \li|\cb{empty}

         An empty project that can be filled with packages (see
         \cb{--package}). Note that the project language is ignored for this
         project type. Recognized empty project sub-options:|

     \li|\n\ \ \ \cb{no-readme}

         See \cb{common} sub-options below.||

     \dl|

     \li|\cb{common}

         Common project type sub-options:|

     \li|\n\ \ \ \c{\b{license=}\i{name}}

         Specify the project's license. Commonly used license names are
         \cb{MIT}, \cb{ASLv2} (Apache License 2.0), \cb{GPLv3}, and
         \cb{proprietary}. If unspecified, then \cb{proprietary} is
         assumed. See the \l{bpkg#manifest-package-license \cb{license}}
         package manifest value for details.|

     \li|\n\ \ \ \cb{no-readme}

         Don't add \cb{README.md}.|

     \li|\n\ \ \ \cb{alt-naming}

         Use the alternative build file/directory naming scheme.||

     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{c}

         A C project.||

     \dl|

     \li|\cb{c++}

         A C++ project. Recognized language sub-options:|

     \li|\n\ \ \ \cb{binless}

         Create a header-only library.|

     \li|\n\ \ \ \cb{cpp}

         Use the \cb{.cpp}, \cb{.hpp}, \cb{.ipp}, \cb{.tpp}, and \cb{.mpp}
         source file extensions (alias for \cb{extension=?pp}).|

     \li|\n\ \ \ \c{\b{extension=}\i{pattern}}

         Derive source file extensions from \ci{pattern} by replacing
         every \cb{?} with one of the \cb{c} (source), \cb{h} (header),
         \cb{i} (inline), \cb{t} (template), or \cb{m} (module interface)
         letters. If unspecified and no individual extensions are specified
         with the below options, then \cb{?xx} is used by default.|

     \li|\n\ \ \ \c{\b{hxx=}\i{extension}}

         Use the specified \ci{extension} for header files instead of
         the default \cb{.hxx}.|

     \li|\n\ \ \ \c{\b{cxx=}\i{extension}}

         Use the specified \ci{extension} for source files instead of
         the default \cb{.cxx}.|

     \li|\n\ \ \ \c{\b{ixx=}\i{extension}}

         Use the specified \ci{extension} for inline files. If
         unspecified, then assume no inline files are used by the
         project.|

     \li|\n\ \ \ \c{\b{txx=}\i{extension}}

         Use the specified \ci{extension} for template files. If
         unspecified, then assume no template files are used by the
         project.|

     \li|\n\ \ \ \c{\b{mxx=}\i{extension}}

         Use the specified \ci{extension} for module interface files. If
         unspecified, then assume no modules are used by the project.||

     As an example, the following command creates a header-only C++ library
     that uses the \cb{.h} extension for header files and \cb{.cpp} \- for
     source files:

     \
     $ bdep new -t lib -l c++,binless,hxx=h,cxx=cpp libhello
     \

     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.||

     \dl|

     \li|\cb{none}

         Don't initialize a version control system inside the project.||

     The newly created project, package, or subdirectory can be further
     customized using the post-creation hooks specified with the
     \cb{--post-hook} option. The hook commands are executed in the
     newly created project, package, or source directory as their
     current working directory. For example:

     \
     $ bdep new --post-hook \"echo .idea/ >>.gitignore\" hello
     \

     See the \cb{--post-hook} option documentation below for details.
     "
  }

  //--type options
  //
  class cmd_new_exe_options
  {
    bool no-tests;
    bool unit-tests;
    string license = "proprietary";
    bool no-readme;
    bool alt-naming;
  };

  class cmd_new_lib_options
  {
    bool no-tests;
    bool unit-tests;
    bool no-version;
    string license = "proprietary";
    bool no-readme;
    bool alt-naming;
  };

  class cmd_new_bare_options
  {
    bool no-tests;
    string license = "proprietary";
    bool no-readme;
    bool alt-naming;
  };

  class cmd_new_empty_options
  {
    bool no-readme;
  };

  // --lang options
  //
  class cmd_new_c_options
  {
  };

  // The cpp flag is the "extension=?pp" alias and is mutually exclusive with
  // extension=.
  //
  class cmd_new_cxx_options
  {
    bool binless;
    bool cpp;
    string extension;
    string hxx;
    string cxx;
    string ixx;
    string txx;
    string mxx;
  };

  // --vcs options
  //
  class cmd_new_git_options
  {
  };

  class cmd_new_none_options
  {
  };

  class cmd_new_options: configuration_add_options, configuration_name_options
  {
    "\h|NEW OPTIONS|"

    bool --no-init
    {
      "Don't initialize an empty build configuration set."
    }

    bool --package
    {
      "Create a new package inside an already existing project rather than a
       new project."
    }

    bool --subdirectory
    {
      "Create a new source subdirectory inside an already existing project or
       package rather than a new project."
    }

    dir_path --output-dir|-o
    {
      "<dir>",
      "Create the project, package, or source subdirectory in the specified
       directory."
    }

    dir_path --directory|-d
    {
      "<dir>",
      "Assume the project/package is in the specified directory rather than
       in the current working directory. Only used with \cb{--package} or
       \cb{--subdirectory}."
    }

    cmd_new_type --type|-t
    {
      "<type>[,<opt>...]",
      "Specify project type and options. Valid values for <type> are \cb{exe}
       (executable project, default), \cb{lib} (library project), \cb{bare}
       (bare project without any source code), and \cb{empty} (empty project
       ready to be filled with packages). Valid values for <opt> are
       type-specific."
    }

    cmd_new_lang --lang|-l
    {
      "<lang>[,<opt>...]",
      "Specify project language and options. Valid values for <lang> are \cb{c}
       and \cb{c++} (default). Valid values for <opt> are language-specific."
    }

    cmd_new_vcs --vcs|-s
    {
      "<vcs>[,<opt>...]",
      "Specify project version control system and options. Valid values for
       <vcs> are \cb{git} (default) and \cb{none}. Valid values for <opt> are
       system-specific."
    }

    strings --post-hook
    {
      "<command>",
      "Run the specified command in the newly created project, package, or
       source directory.

       The <command> value is interpreted as a whitespace-separated,
       potentially quoted command line consisting of the program optionally
       followed by arguments and redirects. Specifically, a single level of
       quotes (either single or double) is removed and whitespaces are not
       treated as separators inside such quoted fragments. Currently only the
       \cb{stdout} redirect to a file is supported. For example:

       \
       $ bdep new --post-hook \"echo '.idea/ # IDE' >>.gitignore\" hello
       \

       The command line elements (program, arguments, etc) may optionally
       contain substitutions \- variable names enclosed with the \cb{@}
       substitution symbol \- which are replaced with the corresponding
       variable values to produce the actual command. The following variable
       names are recognized with the double substitution symbol (\cb{@@})
       serving as an escape sequence.

       \
       @mode@ - one of 'project', 'package', or 'subdirectory'
       @name@ - project, package, or subdirectory name
       @base@ - name base (name without extension)
       @stem@ - name stem (name base without 'lib' prefix)
       @type@ - type (--type|-t value: 'exe', 'lib', etc)
       @lang@ - language (--lang|-l value: 'c', 'c++', etc)
       @vcs@  - version control system (--vcs|-s value: 'git', etc)
       @root@ - project/package root directory
       \

       For example:

       \
       $ bdep new --post-hook \"echo bin/ >>@name@/.gitignore\" hello
       \

       These substitution variables are also made available to the hook program
       as the \cb{BDEP_NEW_*} environment variables (\cb{BDEP_NEW_MODE},
       \cb{BDEP_NEW_NAME}, etc)."
    }

    // @@ This should be a no-amalgamation type sub-options.
    //
    bool --no-amalgamation
    {
      "Create a project with disabled amalgamation support. This option is
       normally only used for testing."
    }

    bool --no-checks
    {
      "Suppress nested project/package checks. This option is normally only
       used for testing."
    }

    dir_path --config-add|-A
    {
      "<dir>",
      "Add an existing build configuration <dir>."
    }

    dir_path --config-create|-C
    {
      "<dir>",
      "Create a new build configuration in <dir>."
    }
  };

  "\h|ENVIRONMENT|

   The \cb{BDEP_AUTHOR_EMAIL} environment variable can be used to specify the
   package email address. If not set, the \cb{new} command will first try to
   obtain the email from the version control system (if used) and then from
   the \cb{EMAIL} environment variable. If all these methods fail, a dummy
   \cb{@example.org} email is used.
  "
}