Exemplo n.º 1
0
    def setup(self):
        """
        Command Line Interface.

        Exits the application in the following conditions:

            * user requested the applications version,
            * user requested help or longhelp,
            * can not find the herringfile.

        :return: None
        """

        parser, settings, argv = HerringSettings().parse()

        Logger.set_verbose(not settings.quiet)
        Logger.set_debug(settings.herring_debug)

        TaskWithArgs.argv = argv
        TaskWithArgs.kwargs = ArgumentHelper.argv_to_dict(argv)

        if settings.longhelp:
            info(sys.modules['herring'].__doc__)
            exit(0)

        if settings.version:
            info("Herring version %s" % self._load_version())
            exit(0)

        return settings
Exemplo n.º 2
0
 def test_argvToDict_singleHyphens(self):
     """
     test improperly using single hyphens when the user probably meant double
     hyphens
     """
     argv = ['-flag', 'false',
             '-',
             '-foo', 'alpha', 'beta',
             '-bar', 'delta', '-charlie']
     kwargs = ArgumentHelper.argv_to_dict(argv)
     self.assertEqual(kwargs, {})
Exemplo n.º 3
0
 def test_argvToDict_mixed(self):
     """test with a mixture of arguments"""
     argv = ['--flag', 'false',
             '--foo', 'alpha', 'beta',
             '--bar', 'delta',
             '--charlie']
     expected_kwargs = {'charlie': True,
                        'flag': 'false',
                        'foo': 'alpha beta',
                        'bar': 'delta'}
     kwargs = ArgumentHelper.argv_to_dict(argv)
     self.assertEqual(kwargs, expected_kwargs)
Exemplo n.º 4
0
 def test_argvToDict_doubleHyphensMiddle(self):
     """
     test with multiple arguments where -- is in the middle of the arguments
     """
     argv = ['--flag', 'false',
             '--',
             '--foo', 'alpha', 'beta',
             '--bar', 'delta',
             '--charlie']
     expected_kwargs = {'charlie': True,
                        'flag': 'false',
                        'foo': 'alpha beta',
                        'bar': 'delta'}
     kwargs = ArgumentHelper.argv_to_dict(argv)
     self.assertEqual(kwargs, expected_kwargs)
Exemplo n.º 5
0
 def test_argvToDict_doubleEquals(self):
     """test more than one equal sign in a key argument"""
     self.assertEqual(ArgumentHelper.argv_to_dict(['--foo=bar=alpha']),
                      {'foo': 'bar=alpha'})
Exemplo n.º 6
0
 def test_argvToDict_equals(self):
     """test the --key=value syntax"""
     self.assertEqual(ArgumentHelper.argv_to_dict(['--foo=bar']),
                      {'foo': 'bar'})
Exemplo n.º 7
0
 def test_argvToDict_doubleHyphensBegin(self):
     """test with multiple arguments where the first argument is --"""
     self.assertEqual(ArgumentHelper.argv_to_dict(['--', '--flag']),
                      {'flag': True})
Exemplo n.º 8
0
 def test_argvToDict_doubleHyphens(self):
     """test with just a -- argument"""
     self.assertEqual(ArgumentHelper.argv_to_dict(['--']), {})
Exemplo n.º 9
0
 def test_argvToDict_value(self):
     """test with just a single value, i.e., no key argument"""
     self.assertEqual(ArgumentHelper.argv_to_dict(['fubar']), {})
     self.assertEqual(ArgumentHelper.argv_to_dict(['-fubar']), {})
Exemplo n.º 10
0
 def test_argvToDict_pair(self):
     """test with just a single key value pair of arguments"""
     self.assertEqual(ArgumentHelper.argv_to_dict(['--foo', 'bar']),
                      {'foo': 'bar'})
Exemplo n.º 11
0
 def test_argvToDict_flag(self):
     """test with just a single flag argument"""
     self.assertEqual(ArgumentHelper.argv_to_dict(['--flag']),
                      {'flag': True})
Exemplo n.º 12
0
 def test_argvToDict_empty(self):
     """test with no arguments"""
     self.assertEqual(ArgumentHelper.argv_to_dict([]), {})