hookmeup

A Git hook to automate your Pipenv and Django workflow
git clone git://git.danielmoch.com/hookmeup.git
Log | Files | Refs | README | LICENSE

commit a1fa60be26d43d5130b0d0b8d5f0e9d4d2fe8dc8
parent eab0da457ce4fda1e60af1fb470d626411c97a7c
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Wed, 22 Aug 2018 21:58:15 -0400

Print help when no arguments given

Diffstat:
MMakefile | 4++--
Mhookmeup/__init__.py | 4++++
Mtests/test_main.py | 12++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -74,7 +74,7 @@ install: clean ## install the package to the active Python's site-packages $(PIPENV) flit install run: install ## run the package from site-packages - $(PIPENV) hookmeup install + $(PIPENV) hookmeup debug: install ## debug the package from site packages - $(PIPENV) pudb3 `$(PIPENV) which hookmeup` install + $(PIPENV) pudb3 `$(PIPENV) which hookmeup` diff --git a/hookmeup/__init__.py b/hookmeup/__init__.py @@ -2,6 +2,7 @@ """A Git hook to automate your Pipenv and Django workflows""" import argparse +from argparse import Namespace from . import hookmeup @@ -34,6 +35,9 @@ def main(): help='1 for branch checkout, 0 otherwise') post_commit_parser.set_defaults(func=hookmeup.post_checkout) args = parser.parse_args() + if args == Namespace(): + parser.print_help() + exit(1) func = args.func arg_dict = vars(args) del arg_dict['func'] diff --git a/tests/test_main.py b/tests/test_main.py @@ -68,3 +68,15 @@ def test_pc_too_many_args(mock_hookmeup, mocker): hookmeup.main() assert hookmeup.hookmeup.post_checkout.call_count == 0 assert hookmeup.hookmeup.install.call_count == 0 + +def test_no_args(mock_hookmeup, mocker): + """Test hookmeup called with no arguments""" + mocker.patch.object( + sys, + 'argv', + ['hookmeup'] + ) + with pytest.raises(SystemExit): + hookmeup.main() + hookmeup.hookmeup.post_checkout.assert_not_called() + hookmeup.hookmeup.install.assert_not_called()