How to use the invoke.parser.Context function in invoke

To help you get started, we’ve selected a few invoke examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyinvoke / invoke / tests / parser_parser.py View on Github external
def raises_ValueError_for_unnamed_Contexts_in_contexts(self):
        with raises(ValueError):
            Parser(initial=Context(), contexts=[Context()])
github pyinvoke / invoke / tests / parser / parser.py View on Github external
def can_take_initial_and_other_contexts(self):
        c1 = Context('foo')
        c2 = Context('bar')
        p = Parser(initial=Context(), contexts=[c1, c2])
        eq_(p.contexts['foo'], c1)
        eq_(p.contexts['bar'], c2)
github pyinvoke / invoke / tests / parser / parser.py View on Github external
def returns_only_contexts_mentioned(self):
            task1 = Context('mytask')
            task2 = Context('othertask')
            result = Parser((task1, task2)).parse_argv(['othertask'])
            eq_(len(result), 1)
            eq_(result[0].name, 'othertask')
github pyinvoke / invoke / tests / parser_parser.py View on Github external
def _compare(self, argname, invoke, value):
                c = Context("mytask", args=(Argument(argname, kind=str),))
                r = Parser((c,)).parse_argv(["mytask", invoke])
                assert r[0].args[argname].value == value
github pyinvoke / invoke / tests / parser_parser.py View on Github external
def ignore_unknown_does_not_mutate_rest_of_argv(self):
            p = Parser([Context("ugh")], ignore_unknown=True)
            r = p.parse_argv(["ugh", "what", "-nowai"])
            # NOT: ['what', '-n', '-w', '-a', '-i']
            assert r.unparsed == ["what", "-nowai"]
github pyinvoke / invoke / tests / parser / parser.py View on Github external
def can_take_just_other_contexts(self):
        c = Context('foo')
        p = Parser(contexts=[c])
        eq_(p.contexts['foo'], c)
github pyinvoke / invoke / tests / parser / parser.py View on Github external
def _parser(self, arguments=None):
            if arguments is None:
                arguments = (
                    Argument(
                        names=('foo', 'f'),
                        optional=True,
                        default='mydefault'
                    ),
                )
            self.context = Context('mytask', args=arguments)
            return Parser([self.context])
github pyinvoke / invoke / tests / parser_parser.py View on Github external
def raises_error_for_context_name_and_alias_clashes(self):
        # I.e. inverse of the above, which is a different code path.
        with raises(ValueError):
            Parser((Context("foo"), Context("bar", aliases=("foo",))))
github pyinvoke / invoke / tests / parser_parser.py View on Github external
def iterables_work_correctly_outside_a_vacuum(self):
            # Undetected bug where I was primarily focused on the -vvv use
            # case...'normal' incrementables never left 'waiting for value'
            # state in the parser! so _subsequent_ task names & such never got
            # parsed right, always got appended to the list.
            c = Context("mytask", args=[Argument("mylist", kind=list)])
            c2 = Context("othertask")
            argv = [
                "mytask",
                "--mylist",
                "val",
                "--mylist",
                "val2",
                "othertask",
            ]
            result = Parser([c, c2]).parse_argv(argv)
            # When bug present, result only has one context (for 'mytask') and
            # its 'mylist' consists of ['val', 'val2', 'othertask']. (the
            # middle '--mylist' was handled semi-correctly.)
            mylist = result[0].args.mylist.value
            assert mylist == ["val", "val2"]
            contexts = len(result)
github pyinvoke / invoke / tests / parser_parser.py View on Github external
def by_itself_base_case(self):
                task1 = Context("mytask")
                init = Context(args=[Argument("help", optional=True)])
                parser = Parser(initial=init, contexts=[task1])
                result = parser.parse_argv(["mytask", "--help"])
                assert len(result) == 2
                assert result[0].args.help.value == "mytask"
                assert "help" not in result[1].args