1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""
4Examples::
5
6    $ python geet.py
7    no command given
8
9    $ python geet.py leet
10    unknown command 'leet'
11
12    $ python geet.py --help
13    geet v1.7.2
14    The l33t version control
15
16    Usage: geet.py [SWITCHES] [SUBCOMMAND [SWITCHES]] args...
17    Meta-switches:
18        -h, --help                 Prints this help message and quits
19        -v, --version              Prints the program's version and quits
20
21    Subcommands:
22        commit                     creates a new commit in the current branch; see
23                                   'geet commit --help' for more info
24        push                       pushes the current local branch to the remote
25                                   one; see 'geet push --help' for more info
26
27    $ python geet.py commit --help
28    geet commit v1.7.2
29    creates a new commit in the current branch
30
31    Usage: geet commit [SWITCHES]
32    Meta-switches:
33        -h, --help                 Prints this help message and quits
34        -v, --version              Prints the program's version and quits
35
36    Switches:
37        -a                         automatically add changed files
38        -m VALUE:str               sets the commit message; required
39
40    $ python geet.py commit -m "foo"
41    committing...
42"""
43
44try:
45    import colorama
46
47    colorama.init()
48except ImportError:
49    pass
50
51from plumbum import cli, colors
52
53
54class Geet(cli.Application):
55    SUBCOMMAND_HELPMSG = False
56    DESCRIPTION = colors.yellow | """The l33t version control"""
57    PROGNAME = colors.green
58    VERSION = colors.blue | "1.7.2"
59    COLOR_USAGE_TITLE = colors.bold | colors.magenta
60    COLOR_USAGE = colors.magenta
61
62    _group_names = ["Meta-switches", "Switches", "Sub-commands"]
63
64    COLOR_GROUPS = dict(
65        zip(_group_names, [colors.do_nothing, colors.skyblue1, colors.yellow])
66    )
67
68    COLOR_GROUP_TITLES = dict(
69        zip(
70            _group_names,
71            [colors.bold, colors.bold | colors.skyblue1, colors.bold | colors.yellow],
72        )
73    )
74
75    verbosity = cli.SwitchAttr(
76        "--verbosity",
77        cli.Set("low", "high", "some-very-long-name", "to-test-wrap-around"),
78        help=colors.cyan
79        | "sets the verbosity level of the geet tool. doesn't really do anything except for testing line-wrapping "
80        "in help " * 3,
81    )
82    verbositie = cli.SwitchAttr(
83        "--verbositie",
84        cli.Set("low", "high", "some-very-long-name", "to-test-wrap-around"),
85        help=colors.hotpink
86        | "sets the verbosity level of the geet tool. doesn't really do anything except for testing line-wrapping "
87        "in help " * 3,
88    )
89
90
91@Geet.subcommand(colors.red | "commit")
92class GeetCommit(cli.Application):
93    """creates a new commit in the current branch"""
94
95    auto_add = cli.Flag("-a", help="automatically add changed files")
96    message = cli.SwitchAttr("-m", str, mandatory=True, help="sets the commit message")
97
98    def main(self):
99        print("committing...")
100
101
102GeetCommit.unbind_switches("-v", "--version")
103
104
105@Geet.subcommand("push")
106class GeetPush(cli.Application):
107    """pushes the current local branch to the remote one"""
108
109    tags = cli.Flag("--tags", help="whether to push tags (default is False)")
110
111    def main(self, remote, branch="master"):
112        print("pushing to {}/{}...".format(remote, branch))
113
114
115if __name__ == "__main__":
116    Geet.run()
117