Skip to content

Commit

Permalink
Drop the click dependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ekohl committed Jun 23, 2020
1 parent fe75d43 commit be8e2cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
43 changes: 20 additions & 23 deletions PyGitUp/gitup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
###############################################################################

# Python libs
import argparse
import codecs
import errno
import sys
Expand All @@ -36,7 +37,6 @@
else: # pragma: no cover
NO_DISTRIBUTE = False

import click
import colorama
from git import Repo, GitCmdObjectDB
from termcolor import colored
Expand Down Expand Up @@ -615,46 +615,43 @@ def print_error(self, error):
'''


@click.command(epilog=EPILOG)
@click.option('-V', '--version', is_flag=True,
help='Show version (and if there is a newer version).')
@click.option('-q', '--quiet', is_flag=True,
help='Be quiet, only print error messages.')
@click.option('--no-fetch', '--no-f', is_flag=True,
help='Don\'t try to fetch from origin.')
@click.option('-p', '--push/--no-push', default=None,
help='Push the changes after pulling successfully.')
@click.help_option('-h', '--help')
def run(version, quiet, no_fetch, push, **kwargs): # pragma: no cover
def run(): # pragma: no cover
"""
A nicer `git pull`.
"""
if version:

parser = argparse.ArgumentParser(description="A nicer `git pull`.", epilog=EPILOG)
parser.add_argument('-V', '--version', action='store_true',
help='Show version (and if there is a newer version).')
parser.add_argument('-q', '--quiet', action='store_true',
help='Be quiet, only print error messages.')
parser.add_argument('--no-fetch', '--no-f', dest='fetch', action='store_false',
help='Don\'t try to fetch from origin.')
parser.add_argument('-p', '--push', action='store_true',
help='Push the changes after pulling successfully.')

args = parser.parse_args()

if args.version:
if NO_DISTRIBUTE:
print(colored('Please install \'git-up\' via pip in order to '
'get version information.', 'yellow'))
else:
GitUp(sparse=True).version_info()
return

if quiet:
if args.quiet:
sys.stdout = StringIO()

try:
gitup = GitUp()

if push is not None:
gitup.settings['push.auto'] = push

# if arguments['--no-fetch'] or arguments['--no-f']:
if no_fetch:
gitup.should_fetch = False

gitup.settings['push.auto'] = args.push
gitup.should_fetch = args.fetch
except GitError:
sys.exit(1) # Error in constructor
else:
gitup.run()


if __name__ == '__main__': # pragma: no cover
run(help_option_names=['-h'])
run()
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
GitPython>=2.1.8
colorama>=0.3.7
termcolor>=1.1.0
click>=7.0.0
six>=1.10.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
version="1.6.1",
packages=find_packages(),
install_requires=['GitPython>=2.1.8', 'colorama>=0.3.7',
'termcolor>=1.1.0', 'click>=7.0',
'termcolor>=1.1.0',
'six>=1.10.0'],

# Tests
Expand Down

0 comments on commit be8e2cc

Please sign in to comment.