Exemple #1
0
    def test_help(self):
        proj = Project('foo')
        proj.add_help('General:', False)
        proj.add_alias('--help', ['--help=default'],
                help='display standard help, then exit', hidden=False)
        proj.add_option('--help', init='none',
                type=proj.do_help, check=None,
                help='display some subset of help', hidden=False,
                help_var='TYPE')
        proj.help.add_option('--help=hidden',
                help='display help you should never ever ever care about',
                hidden=True)
        proj.add_option('--foo', init='asdf',
                type=shell_word, check=None,
                help='set frob target', hidden=False)
        proj.add_option('--bar', init='',
                type=maybe(shell_word), check=None,
                help='set frob source', hidden=False,
                help_def='FOO')

        build = Build(proj, 'bar')

        out = StringIO()
        with ReplacingStdout(out):
            with self.assertRaises(SystemExit):
                build.apply_arg('--help')
        self.assertEqual(out.getvalue(), '''
General:
  --help       display standard help, then exit
  --help=TYPE  display some subset of help [none]
  --foo=FOO    set frob target [asdf]
  --bar=BAR    set frob source [FOO]

'''[1:])

        out = StringIO()
        with ReplacingStdout(out):
            with self.assertRaises(SystemExit):
                build.apply_arg('--help=hidden')
        self.assertEqual(out.getvalue(), '''
General:
  --help         display standard help, then exit
  --help=TYPE    display some subset of help [none]
  --help=hidden  display help you should never ever ever care about
  --foo=FOO      set frob target [asdf]
  --bar=BAR      set frob source [FOO]

'''[1:])