Skip to content

Commit f7ebbf6

Browse files
committed
Improve command line interface
1 parent 7d52e3e commit f7ebbf6

File tree

3 files changed

+37
-46
lines changed

3 files changed

+37
-46
lines changed

README.rst

+15-28
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ Command line program to perform common operations (in the context of packaging/d
7272
Alternatively the location of a remote repository can be given. The
7373
location should be prefixed by the type of the repository (with a ""+"" in
7474
between) unless the location ends in "".git"" in which case the prefix is
75-
optional.
76-
"
75+
optional."
7776
"``--rev``, ``--revision=REVISION``","Select a revision to operate on. Accepts any string that's supported by the
7877
VCS system that manages the repository, which means you can provide branch
7978
names, tag names, exact revision ids, etc. This option is used in
@@ -82,55 +81,46 @@ Command line program to perform common operations (in the context of packaging/d
8281

8382
If this option is not provided a default revision is selected: ""last:1"" for
8483
Bazaar repositories, ""master"" for git repositories and ""default"" (not
85-
""tip""!) for Mercurial repositories.
86-
"
84+
""tip""!) for Mercurial repositories."
8785
``--release=RELEASE_ID``,"Select a release to operate on. This option works in the same way as the
8886
``--revision`` option. Please refer to the vcs-repo-mgr documentation for
8987
details on ""releases"".
9088

9189
Although release identifiers are based on branch or tag names they
9290
may not correspond literally, this is why the release identifier you
9391
specify here is translated to a global revision id before being passed to
94-
the VCS system.
95-
"
92+
the VCS system."
9693
"``-n``, ``--find-revision-number``","Print the local revision number (an integer) of the revision given with the
9794
``--revision`` option. Revision numbers are useful as a build number or when a
9895
simple, incrementing version number is required. Revision numbers should
9996
not be used to unambiguously refer to a revision (use revision ids for that
10097
instead). This option is used in combination with the ``--repository`` and
101-
``--revision`` options.
102-
"
98+
``--revision`` options."
10399
"``-i``, ``--find-revision-id``","Print the global revision id (a string) of the revision given with the
104100
``--revision`` option. Global revision ids are useful to unambiguously refer to
105101
a revision. This option is used in combination with the ``--repository`` and
106-
``--revision`` options.
107-
"
102+
``--revision`` options."
108103
``--list-releases``,"Print the identifiers of the releases in the repository given with the
109104
``--repository`` option. The release identifiers are printed on standard
110-
output (one per line), ordered using natural order comparison.
111-
"
105+
output (one per line), ordered using natural order comparison."
112106
``--select-release=RELEASE_ID``,"Print the identifier of the newest release that is not newer than
113107
``RELEASE_ID`` in the repository given with the ``--repository`` option.
114-
The release identifier is printed on standard output.
115-
"
108+
The release identifier is printed on standard output."
116109
"``-s``, ``--sum-revisions``","Print the summed revision numbers of multiple repository/revision pairs.
117110
The repository/revision pairs are taken from the positional arguments to
118111
vcs-repo-mgr.
119112

120113
This is useful when you're building a package based on revisions from
121114
multiple VCS repositories. By taking changes in all repositories into
122115
account when generating version numbers you can make sure that your version
123-
number is bumped with every single change.
124-
"
116+
number is bumped with every single change."
125117
``--vcs-control-field``,"Print a line containing a Debian control file field and value. The field
126118
name will be one of ""Vcs-Bzr"", ""Vcs-Hg"" or ""Vcs-Git"". The value will be the
127119
repository's remote location and the selected revision (separated by a ""#""
128-
character).
129-
"
120+
character)."
130121
"``-u``, ``--update``","Create/update the local clone of a remote repository by pulling the latest
131122
changes from the remote repository. This option is used in combination with
132-
the ``--repository`` option.
133-
"
123+
the ``--repository`` option."
134124
"``-m``, ``--merge-up``","Merge a change into one or more release branches and the default branch.
135125

136126
By default merging starts from the current branch. You can explicitly
@@ -144,17 +134,14 @@ Command line program to perform common operations (in the context of packaging/d
144134

145135
If the feature branch is located in a different repository you can prefix
146136
the location of the repository to the name of the feature branch with a ""#""
147-
token in between, to delimit the location from the branch name.
148-
"
137+
token in between, to delimit the location from the branch name."
149138
"``-e``, ``--export=DIRECTORY``","Export the contents of a specific revision of a repository to a local
150139
directory. This option is used in combination with the ``--repository`` and
151-
``--revision`` options.
152-
"
140+
``--revision`` options."
153141
"``-d``, ``--find-directory``","Print the absolute pathname of a local repository. This option is used in
154-
combination with the ``--repository`` option.
155-
"
156-
"``-v``, ``--verbose``","Make more noise.
157-
"
142+
combination with the ``--repository`` option."
143+
"``-v``, ``--verbose``",Increase logging verbosity (can be repeated).
144+
"``-q``, ``--quiet``",Decrease logging verbosity (can be repeated).
158145
"``-h``, ``--help``","Show this message and exit.
159146
"
160147

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
coloredlogs >= 0.5
1+
coloredlogs >= 6.1
22
executor >= 1.2
33
humanfriendly >= 1.44.4
44
naturalsort >= 1.3

vcs_repo_mgr/cli.py

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Command line interface for vcs-repo-mgr.
22
#
33
# Author: Peter Odding <peter@peterodding.com>
4-
# Last Change: March 18, 2016
4+
# Last Change: April 29, 2017
55
# URL: https://github.com/xolox/python-vcs-repo-mgr
66

77
"""
@@ -129,7 +129,11 @@
129129
130130
-v, --verbose
131131
132-
Make more noise.
132+
Increase logging verbosity (can be repeated).
133+
134+
-q, --quiet
135+
136+
Decrease logging verbosity (can be repeated).
133137
134138
-h, --help
135139
@@ -145,6 +149,7 @@
145149
# External dependencies.
146150
import coloredlogs
147151
from executor import execute
152+
from humanfriendly.terminal import usage, warning
148153

149154
# Modules included in our package.
150155
from vcs_repo_mgr import coerce_repository, sum_revision_numbers
@@ -157,9 +162,7 @@
157162

158163

159164
def main():
160-
"""
161-
The command line interface of the ``vcs-tool`` command.
162-
"""
165+
"""The command line interface of the ``vcs-tool`` program."""
163166
# Initialize logging to the terminal.
164167
coloredlogs.install()
165168
# Command line option defaults.
@@ -168,11 +171,11 @@ def main():
168171
actions = []
169172
# Parse the command line arguments.
170173
try:
171-
options, arguments = getopt.gnu_getopt(sys.argv[1:], 'r:dnisume:vh', [
174+
options, arguments = getopt.gnu_getopt(sys.argv[1:], 'r:dnisume:vqh', [
172175
'repository=', 'rev=', 'revision=', 'release=', 'find-directory',
173176
'find-revision-number', 'find-revision-id', 'list-releases',
174177
'select-release=', 'sum-revisions', 'vcs-control-field', 'update',
175-
'merge-up', 'export=', 'verbose', 'help'
178+
'merge-up', 'export=', 'verbose', 'quiet', 'help',
176179
])
177180
for option, value in options:
178181
if option in ('-r', '--repository'):
@@ -183,6 +186,12 @@ def main():
183186
revision = value.strip()
184187
assert revision, "Please specify a nonempty revision string!"
185188
elif option == '--release':
189+
# TODO Right now --release and --merge-up cannot be combined
190+
# because the following statements result in a global
191+
# revision id which is immutable. If release objects had
192+
# something like an optional `mutable_revision_id' it
193+
# should be possible to support the combination of
194+
# --release and --merge-up.
186195
assert repository, "Please specify a repository first!"
187196
release_id = value.strip()
188197
assert release_id in repository.releases, "The given release identifier is invalid!"
@@ -228,16 +237,16 @@ def main():
228237
actions.append(functools.partial(repository.export, directory, revision))
229238
elif option in ('-v', '--verbose'):
230239
coloredlogs.increase_verbosity()
240+
elif option in ('-q', '--quiet'):
241+
coloredlogs.decrease_verbosity()
231242
elif option in ('-h', '--help'):
232-
usage()
243+
usage(__doc__)
233244
return
234245
if not actions:
235-
usage()
246+
usage(__doc__)
236247
return
237248
except Exception as e:
238-
logger.error(e)
239-
print('')
240-
usage()
249+
warning("Error: %s", e)
241250
sys.exit(1)
242251
# Execute the requested action(s).
243252
try:
@@ -281,8 +290,3 @@ def print_summed_revisions(arguments):
281290
def print_vcs_control_field(repository, revision):
282291
"""Report the VCS control field for the given repository and revision to standard output."""
283292
print("%s: %s" % repository.generate_control_field(revision))
284-
285-
286-
def usage():
287-
"""Report the usage message to standard output."""
288-
print(__doc__.strip())

0 commit comments

Comments
 (0)