Skip to content

Commit 215b1c4

Browse files
authored
refactor: drop the click dependency (#96)
This reduces the number of external dependencies and relies more on Python's standard library. It drops the --no-push option since argparse doesn't support having a --option / --no-option. That's also the default and this makes it clearer to the user what the default is. The help text's formatting is slightly different. Mostly visible are that the description and epilog are no longer indented.
1 parent 01f74a3 commit 215b1c4

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

PyGitUp/gitup.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
###############################################################################
99

1010
# Python libs
11+
import argparse
1112
import codecs
1213
import errno
1314
import sys
@@ -29,7 +30,6 @@
2930
else: # pragma: no cover
3031
NO_DISTRIBUTE = False
3132

32-
import click
3333
import colorama
3434
from git import Repo, GitCmdObjectDB
3535
from termcolor import colored
@@ -534,46 +534,43 @@ def print_error(self, error):
534534
'''
535535

536536

537-
@click.command(epilog=EPILOG)
538-
@click.option('-V', '--version', is_flag=True,
539-
help='Show version (and if there is a newer version).')
540-
@click.option('-q', '--quiet', is_flag=True,
541-
help='Be quiet, only print error messages.')
542-
@click.option('--no-fetch', '--no-f', is_flag=True,
543-
help='Don\'t try to fetch from origin.')
544-
@click.option('-p', '--push/--no-push', default=None,
545-
help='Push the changes after pulling successfully.')
546-
@click.help_option('-h', '--help')
547-
def run(version, quiet, no_fetch, push, **kwargs): # pragma: no cover
537+
def run(): # pragma: no cover
548538
"""
549539
A nicer `git pull`.
550540
"""
551-
if version:
541+
542+
parser = argparse.ArgumentParser(description="A nicer `git pull`.", epilog=EPILOG)
543+
parser.add_argument('-V', '--version', action='store_true',
544+
help='Show version (and if there is a newer version).')
545+
parser.add_argument('-q', '--quiet', action='store_true',
546+
help='Be quiet, only print error messages.')
547+
parser.add_argument('--no-fetch', '--no-f', dest='fetch', action='store_false',
548+
help='Don\'t try to fetch from origin.')
549+
parser.add_argument('-p', '--push', action='store_true',
550+
help='Push the changes after pulling successfully.')
551+
552+
args = parser.parse_args()
553+
554+
if args.version:
552555
if NO_DISTRIBUTE:
553556
print(colored('Please install \'git-up\' via pip in order to '
554557
'get version information.', 'yellow'))
555558
else:
556559
GitUp(sparse=True).version_info()
557560
return
558561

559-
if quiet:
562+
if args.quiet:
560563
sys.stdout = StringIO()
561564

562565
try:
563566
gitup = GitUp()
564-
565-
if push is not None:
566-
gitup.settings['push.auto'] = push
567-
568-
# if arguments['--no-fetch'] or arguments['--no-f']:
569-
if no_fetch:
570-
gitup.should_fetch = False
571-
567+
gitup.settings['push.auto'] = args.push
568+
gitup.should_fetch = args.fetch
572569
except GitError:
573570
sys.exit(1) # Error in constructor
574571
else:
575572
gitup.run()
576573

577574

578575
if __name__ == '__main__': # pragma: no cover
579-
run(help_option_names=['-h'])
576+
run()

poetry.lock

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ classifiers = [
2929
[tool.poetry.dependencies]
3030
python = "^3.7"
3131
GitPython = "^3.0.0"
32-
click = "^8.0"
3332
colorama = "^0.4.0"
3433
termcolor = "^1.1.0"
3534

0 commit comments

Comments
 (0)