Beispiel #1
0
 def __init__(self):
     self.twoOptsParser = cliparser.CliParser(
         [PosArg("in-file"), PosArg("outFile")])
     self.inFilesWithOpts = self.inFilesParser(addOpts=[
         OptArg("foo", noOfArgs="1"),
         OptArg("bar", noOfArgs="0"),
         OptArg("rest", noOfArgs="*")
     ])
     self.parserWithShortOpts = cliparser.CliParser([
         OptArg("full", "f"),
         OptArg("boolean", "b"),
         OptArg("pattern", "p", noOfArgs="1")
     ])
     self.plusParser = cliparser.CliParser(
         [OptArg("opt"), PosArg("foo", noOfArgs="+")])
     self.parserWithGroups = cliparser.CliParser([
         OptArg("test", noOfArgs="1"),
         SubGroups(SubGroup("foo", OptArg("first", "f"),
                            PosArg("rest", noOfArgs="*")),
                   SubGroup(("bar", "two"), OptArg("second", "s"),
                            SubGroups(
                                SubGroup(
                                    "sub1", OptArg("rest", noOfArgs="*"),
                                    SubGroups(SubGroup("sub11"),
                                              SubGroup("sub12"))),
                                SubGroup("sub2", OptArg("abc")))),
                   SubGroup(
                       "quux",
                       SubGroups(SubGroup("quuxsub1"),
                                 SubGroup("quuxsub2",
                                          PosArg("rest", noOfArgs="*")),
                                 default="quuxsub2")),
                   default="foo")
     ])
Beispiel #2
0
    def __init__(self):
        rulePatterns = PosArg("rule-patterns", noOfArgs="+")
        listFilesLike = [
            PosArg("file"),
            PosArg("version-substrings", noOfArgs="+")
        ]

        self.parser = cliparser.CliParser(GlobalOpts + [
            SubGroups(SubGroup(
                ("list", "ls"),
                SubGroups(SubGroup("schedulers"),
                          SubGroup("synchronizers"),
                          SubGroup("rules", OptArg("full", "f"),
                                   OptArg("show-sys"),
                                   PosArg("rule-patterns", noOfArgs="*")),
                          SubGroup("all"),
                          default="rules")),
                      SubGroup("schedule", OptArg("dry"), rulePatterns),
                      SubGroup("sync", PosArg("rule-name"), description=None),
                      SubGroup("versions-of", PosArg("file")),
                      SubGroup("restore", OptArg("to", noOfArgs="1"),
                               OptArg("force"), *listFilesLike),
                      SubGroup("list-files", OptArg("null"),
                               OptArg("recursive", "r"), *listFilesLike),
                      SubGroup("check", rulePatterns),
                      SubGroup("show", rulePatterns),
                      SubGroup("enable", PosArg("rule-name"),
                               OptArg("as", noOfArgs="1"),
                               PosArg("lines", noOfArgs="*")),
                      SubGroup("disable", PosArg("rule-name")),
                      SubGroup("execute-rule",
                               PosArg("rule-name"),
                               description=None),
                      default="list")
        ])
Beispiel #3
0
def test_shouldParseOptionalsInterleavedInWhateverWay(fixture):
    parserWithBool = cliparser.CliParser([OptArg("do-that")])
    assert parserWithBool.parseArgs(["--do-that"]).values == {"do-that": True}
    assert parserWithBool.parseArgs([]).values == {"do-that": False}

    parserWithVal = cliparser.CliParser([OptArg("some-dir", noOfArgs="1")])
    assert parserWithVal.parseArgs(["--some-dir", "foo"]).values == \
        {"some-dir": "foo"}
    assert parserWithVal.parseArgs([]).values == {}
    assert parserWithVal.parseArgs(["--some-dir=bar"]).values == \
        {"some-dir": "bar"}

    assert fixture.inFilesWithOpts.parseArgs([
        "a", "b", "c", "--bar", "d", "--rest", "a", "b", "--foo=test"]).values ==\
            dict(output="a", inFiles=["b", "c", "d"], bar=True, foo="test",
            rest=["a", "b"])

    assert fixture.parserWithShortOpts.parseArgs(["-f"]).values == \
        dict(full=True, boolean=False)
    assert fixture.parserWithShortOpts.parseArgs(["-fb", "-pfoo"]).values == \
        dict(full=True, boolean=True, pattern="foo")
    assert fixture.parserWithShortOpts.parseArgs(["-fbpbar"]).values == \
        dict(full=True, boolean=True, pattern="bar")
Beispiel #4
0
 def inFilesParser(self, noOfArgs="*", addOpts=[]):
     return cliparser.CliParser(
         [PosArg("output"),
          PosArg("inFiles", noOfArgs=noOfArgs)] + addOpts)
Beispiel #5
0
def test_shouldFirstChooseGroupsWithShorterNames(fixture):
    parser = cliparser.CliParser(
        [SubGroups(SubGroup("list-files"), SubGroup("list"))])

    assert parser.parseArgs(["lis"]).values["command"] == "list"