forked from janluke/cloup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_sections.py
82 lines (64 loc) · 2.84 KB
/
git_sections.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
This example shows how to use ``cloup.Section`` to organize the subcommands of
a multi-command in many ``--help`` sections.
The code was generated by parsing ``git --help`` and taking
- the first 3 sections;
- for each section, the first 3 commands after shuffling them.
"""
# flake8: noqa E128
import cloup
def f(**kwargs):
"""Dummy command callback."""
print(**kwargs)
# In a real big application, you would import the following commands from separate modules =========
git_clone = cloup.command('clone', help='Clone a repository into a new directory')(f)
git_init = cloup.command('init', help='Create an empty Git repository or reinitialize an existing one')(f)
git_rm = cloup.command('rm', help='Remove files from the working tree and from the index')(f)
git_sparse_checkout = cloup.command('sparse-checkout', help='Initialize and modify the sparse-checkout')(f)
git_mv = cloup.command('mv', help='Move or rename a file, a directory, or a symlink')(f)
git_status = cloup.command('status', help='Show the working tree status')(f)
git_diff = cloup.command('diff', help='Show changes between commits, commit and working tree, etc')(f)
git_bisect = cloup.command('bisect', help='Use binary search to find the commit that introduced a bug')(f)
# ==================================================================================================
# If "align_sections=True" (default), the help column of all sections will
# be aligned; otherwise, each section will be formatted independently.
@cloup.group('git', align_sections=True)
def git():
return 0
"""
git.section() creates a new Section object, adds it to git and returns it.
In the help, sections are shown in the same order they are added.
Commands in each sections are shown in the same order they are listed, unless
you pass the argument "sorted=True".
"""
git.section(
'Start a working area (see also: git help tutorial)',
git_clone,
git_init,
)
git.section(
'Work on the current change (see also: git help everyday)',
git_rm,
git_sparse_checkout,
git_mv,
)
git.section(
'Examine the history and state (see also: git help revisions)',
git_status,
git_diff,
git_bisect,
)
"""
In alternative, you can either:
- pass a list of Section objects as argument "sections" to cloup.Group or @cloup.group
- use git.add_section(section) to add an existing Section object
- use git.add_command(cmd, name, section, ...); the section must NOT contain the command
- use @git.command(cmd, name, section, ...)
Individual commands don't store the section they belong to.
Also, cloup.command doesn't accept a "section" argument.
"""
# The following commands will be added to the "default section" (a sorted Section)
git.add_command(cloup.command('fake-2', help='Fake command #2')(f))
git.add_command(cloup.command('fake-1', help='Fake command #1')(f))
if __name__ == '__main__':
git()