waf: use better style for add_option() calls

Setting the "help" keyword argument may not fit in one line sometimes. This
patch adds the following convention to calls to add_option() in order to
address that issue in a better way:

    1) The "help" keyword must always be the last argument to be passed.

    2) If the help string is a literal string or a literal string with some
    operation (e.g. "%" operator) and setting the "help" keyword in the code
    doesn't fit a line (considering the limit of characters in a line), then
    the help string must be a triple-quoted string. That has the advantage of
    not having to have several "+" operations for long help strings. In that
    case, the help message must start on the next line and the closing
    triple-quotes must be on a separate line together with the closing
    parenthesis.

The requirement (1) makes it easier to make the style exception in (2)
acceptable.
This commit is contained in:
Gustavo Jose de Sousa 2016-05-23 10:48:39 -03:00 committed by Lucas De Marchi
parent 64b8ec61c7
commit afcabda21c
2 changed files with 32 additions and 25 deletions

View File

@ -366,25 +366,29 @@ def _select_programs_from_group(bld):
def options(opt): def options(opt):
g = opt.ap_groups['build'] g = opt.ap_groups['build']
g.add_option('--program-group', g.add_option('--program-group',
action='append', action='append',
default=[], default=[],
help='Select all programs that go in <PROGRAM_GROUP>/ for the ' + help='''
'build. Example: `waf --program-group examples` builds all ' + Select all programs that go in <PROGRAM_GROUP>/ for the build. Example: `waf
'examples. The special group "all" selects all programs.', --program-group examples` builds all examples. The special group "all" selects
) all programs.
''')
g.add_option('--upload', g.add_option('--upload',
action='store_true', action='store_true',
help='Upload applicable targets to a connected device. Not all ' + help='''
'platforms may support this. Example: `waf copter --upload` ' + Upload applicable targets to a connected device. Not all platforms may support
'means "build arducopter and upload it to my board".', this. Example: `waf copter --upload` means "build arducopter and upload it to
) my board".
''')
g = opt.ap_groups['check'] g = opt.ap_groups['check']
g.add_option('--check-verbose', g.add_option('--check-verbose',
action='store_true', action='store_true',
help='Output all test programs') help='Output all test programs.')
def build(bld): def build(bld):

33
wscript
View File

@ -52,29 +52,32 @@ def options(opt):
opt.load('ardupilotwaf') opt.load('ardupilotwaf')
g = opt.ap_groups['configure'] g = opt.ap_groups['configure']
boards_names = boards.get_boards_names() boards_names = boards.get_boards_names()
g.add_option('--board', g.add_option('--board',
action='store', action='store',
choices=boards_names, choices=boards_names,
default='sitl', default='sitl',
help='Target board to build, choices are %s' % boards_names) help='Target board to build, choices are %s.' % boards_names)
g.add_option('--no-submodule-update', g.add_option('--no-submodule-update',
dest='submodule_update', dest='submodule_update',
action='store_false', action='store_false',
default=True, default=True,
help='Don\'t update git submodules. Useful for building ' + help='''
'with submodules at specific revisions.') Don't update git submodules. Useful for building with submodules at specific
revisions.
''')
g.add_option('--enable-benchmarks', g.add_option('--enable-benchmarks',
action='store_true', action='store_true',
default=False, default=False,
help='Enable benchmarks') help='Enable benchmarks.')
g.add_option('--debug', g.add_option('--debug',
action='store_true', action='store_true',
default=False, default=False,
help='Configure as debug variant') help='Configure as debug variant.')
def configure(cfg): def configure(cfg):
cfg.env.BOARD = cfg.options.board cfg.env.BOARD = cfg.options.board