Skip to content

Commit

Permalink
Added -v argument support to enable verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Dec 26, 2020
1 parent 3f5e660 commit 373d84d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ New features
* The GitHub username is no longer required upon obtaining organizations list.
* Provided ability to pass authentication token for github.com API requests via
environment variables.
* Added ``-v`` argument support to enable verbose mode.

Packaging changes
~~~~~~~~~~~~~~~~~
Expand Down
15 changes: 10 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Usage

::

gstore [-h] [--token TOKEN] [--org [ORG ...]] [target]
gstore [-h] [--token TOKEN] [--org [ORG ...]] [-v] [target]

**Positional arguments:**

Expand All @@ -121,15 +121,19 @@ Usage
CLI argument, then environment variable will be used. The order of searching
for a token in environment variables as follows (in order of precedence):

* ``GH_TOKEN``, ``GITHUB_TOKEN``
* ``GH_ENTERPRISE_TOKEN``, ``GITHUB_ENTERPRISE_TOKEN``
#. ``GH_TOKEN``, ``GITHUB_TOKEN``
#. ``GH_ENTERPRISE_TOKEN``, ``GITHUB_ENTERPRISE_TOKEN``

Setting these variables allows you not to not pass token directly via CLI
argument and avoids storing it in the Shell history.

``--org [ORG ...]``
Organizations you have access to (by default all).

``-v``, ``--verbose``
Enable verbose mode. Causes Gstore to print debugging messages about its
progress in some cases.

Examples
~~~~~~~~

Expand All @@ -143,7 +147,8 @@ username, and the second one to get a list of user's organizations.
$ gstore --token "$TOKEN" ~/backup
Unless you set the ``GSTORE_DIR`` environment variable and don't provide
*target*, Gstore will sync all the repositories to current working directory.:
*target directory*, Gstore will sync all the repositories to current working
directory.:

.. code-block:: bash
Expand All @@ -166,7 +171,7 @@ To get all repositories of a specific organization, just specify it as follows:
$ gstore --org Acme --token "$TOKEN" ~/backup
To specify a *target* directory right after organization list use double dash
To specify a *target directory* right after organization list use double dash
to signify the end of org option.:

.. code-block:: bash
Expand Down
9 changes: 6 additions & 3 deletions gstore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ def argparse():
p = ArgumentParser(
description="Synchronize organizations' repositories from GitHub.")

p.add_argument('target', nargs='?',
default=env.get('GSTORE_DIR', os.getcwd()),
help='base target to sync repos (e.g. folder on disk)')

p.add_argument('--token', dest='token', default=get_token_from_env(),
help='an authentication token for github.com API requests')
p.add_argument('--org', dest='org', nargs='*',
help='organizations you have access to (by default all)')
p.add_argument('target', nargs='?',
default=env.get('GSTORE_DIR', os.getcwd()),
help='base target to sync repos (e.g. folder on disk)')
p.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='enable verbose mode')

return p.parse_args()
2 changes: 1 addition & 1 deletion gstore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def main():
ns = argparse()
setup_logger()
setup_logger(verbose=ns.verbose)

logger = logging.getLogger('gstore.cli')

Expand Down
16 changes: 8 additions & 8 deletions gstore/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def filter(self, record: logging.LogRecord) -> bool:
return record.levelno == logging.INFO


def setup_logger(*args, **kwargs):
def setup_logger(verbose=False):
"""
Setup and return the root logger object for the application.
"""
Expand All @@ -62,22 +62,22 @@ def setup_logger(*args, **kwargs):
f = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
formatter = logging.Formatter(f)

debug_handler = logging.StreamHandler(sys.stdout)
debug_handler.setLevel(logging.DEBUG)
debug_handler.addFilter(DebugFilter())
debug_handler.setFormatter(formatter)
if verbose:
debug_handler = logging.StreamHandler(sys.stdout)
debug_handler.setLevel(logging.DEBUG)
debug_handler.addFilter(DebugFilter())
debug_handler.setFormatter(formatter)
root.addHandler(debug_handler)

info_handler = logging.StreamHandler(sys.stdout)
info_handler.setLevel(logging.INFO)
info_handler.addFilter(InfoFilter())
info_handler.setFormatter(formatter)
root.addHandler(info_handler)

error_handler = logging.StreamHandler(sys.stderr)
error_handler.setLevel(logging.WARNING)
error_handler.setFormatter(formatter)

root.addHandler(debug_handler)
root.addHandler(info_handler)
root.addHandler(error_handler)

return root
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gitpython==3.0.6
PyGithub==1.54.1
gitpython==3.0.6
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def get_version_string(pkg_dir, pkg_name):

# Dependencies that are downloaded by pip on installation and why
install_requires=[
'gitpython>=3.0.6', # Interact with Git repositories
'PyGithub>=1.54.1', # Interact with GitHub objects
'gitpython>=3.0.6', # Interact with Git repositories
],

# Entry points
Expand Down

0 comments on commit 373d84d

Please sign in to comment.