Skip to content

Commit

Permalink
new: removed the need of the show positional argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaab committed Feb 21, 2017
1 parent 6c4d40e commit ce9843a
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 51 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,16 @@ only a subpart of your changelog. Usually this makes sense:
edition if needed.


You can use then ``gitchangelog show REVLIST``. Examples follows::
You can use then ``gitchangelog REVLIST``. Examples follows::

## will output only tags between 0.0.2 (excluded) and 0.0.3 (included)
gitchangelog show 0.0.2..0.0.3
gitchangelog 0.0.2..0.0.3

## will output only tags since 0.0.3 (excluded)
gitchangelog show ^0.0.3
gitchangelog ^0.0.3

## will output all tags up to 0.0.3 (included)
gitchangelog show 0.0.3
gitchangelog 0.0.3

Additionally, ``gitchangelog`` can figure out which revision is the
last for you (with some little help). This is done by specifying the
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ build: false

test_script:
- "python src\\gitchangelog\\gitchangelog.py --debug"
- "python src\\gitchangelog\\gitchangelog.py --debug show e98a0fe8^^..e98a0fe8"
- "python src\\gitchangelog\\gitchangelog.py --debug e98a0fe8^^..e98a0fe8"

44 changes: 17 additions & 27 deletions src/gitchangelog/gitchangelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
usage_msg = """
%(exname)s {-h|--help}
%(exname)s {-v|--version}
%(exname)s show [REVLIST]"""
%(exname)s [--debug|-d] [REVLIST]"""

description_msg = """\
Run this command in a git repository to output a formatted changelog
Expand Down Expand Up @@ -1384,28 +1384,22 @@ def parse_cmd_line(usage, description, epilog, exname, version):
parser.add_argument('-d', '--debug',
help="Enable debug mode (show full tracebacks).",
action="store_true", dest="debug")

subparsers = parser.add_subparsers(help='commands', dest='action',
prog=exname)
show_parser = subparsers.add_parser(
'show', help='Prints current changelog.',
usage='%(exname)s show [REVLIST]' % {'exname': exname})
show_parser.add_argument('revlist', nargs='*', action="store", default=[])

## Python argparse in 2.7 doesn't like --debug to be after
## positional argument.
argv = sys.argv[1:]
if "--debug" in argv:
argv.remove("--debug")
argv = ["--debug", ] + argv
if "-d" in argv:
argv.remove("-d")
argv = ["-d", ] + argv
if len([action for action in argv if not action.startswith("-")]) == 0:
## Then we don't have positional argument, and this won't be supported
## by argparse from python 2.7. See http://bugs.python.org/issue9253
## so let's cheat and add "show" if no action.
argv += ["show", ]
parser.add_argument('revlist', nargs='*', action="store", default=[])

## Remove "show" as first argument for compatibility reason.

argv = []
for i, arg in enumerate(sys.argv[1:]):
if arg.startswith("-"):
argv.append(arg)
continue
if arg == "show":
warn("'show' positional argument is deprecated.")
argv += sys.argv[i+2:]
break
else:
argv += sys.argv[i+1:]
break

return parser.parse_args(argv)

Expand Down Expand Up @@ -1481,10 +1475,6 @@ def main():
debug_varname = "DEBUG_%s" % basename.upper()
DEBUG = os.environ.get(debug_varname, False)

## Support legacy call of ``gitchangelog`` without arguments
if len(sys.argv) == 1:
sys.argv.append("show")

i = lambda x: x % {'exname': basename}

opts = parse_cmd_line(usage=i(usage_msg),
Expand Down
146 changes: 128 additions & 18 deletions test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ def test_simple_run_no_args_legacy_call(self):
self.REFERENCE.split("\n"),
lineterm="")))

def test_simple_run_show_call(self):
def test_simple_run_show_call_deprecated(self):
out, err, errlvl = cmd('$tprog show')
self.assertEqual(
errlvl, 0,
msg="Should not fail on simple repo and without config file")
self.assertEqual(
err, "",
msg="There should be no standard error outputed. "
self.assertContains(
err, "deprecated",
msg="There should be a warning about deprecated calls. "
"Current stderr:\n%r" % err)
self.assertContains(
out, "0.0.2",
Expand All @@ -177,7 +177,43 @@ def test_simple_run_show_call(self):
self.REFERENCE.split("\n"),
lineterm="")))

def test_simple_show_with_changelog_python_exception(self):
def test_simple_with_changelog_python_exception(self):
w("""
cat <<EOF > .gitchangelog.rc
def raise_exc(data, opts):
raise Exception('Test Exception XYZ')
output_engine = raise_exc
EOF
""")

out, err, errlvl = cmd('$tprog')
self.assertContains(
err, "XYZ",
msg="The exception message should be displayed and thus contain XYZ... "
"Current stderr:\n%s" % err)
self.assertEqual(
errlvl, 255,
msg="Should fail with errlvl 255 if exception in output_engine..."
"Current errlvl: %s" % errlvl)
self.assertContains(
err, "--debug",
msg="Message about ``--debug``... "
"Current stderr:\n%s" % err)
self.assertNotContains(
err, "Traceback (most recent call last):",
msg="The exception message should NOT contain traceback information... "
"Current stderr:\n%s" % err)
self.assertEqual(
out, "",
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_simple_show_with_changelog_python_exception_deprecated(self):
w("""
cat <<EOF > .gitchangelog.rc
Expand All @@ -204,6 +240,10 @@ def raise_exc(data, opts):
err, "--debug",
msg="Message about ``--debug``... "
"Current stderr:\n%s" % err)
self.assertContains(
err, "deprecated",
msg="Message about show being deprecated... "
"Current stderr:\n%s" % err)
self.assertNotContains(
err, "Traceback (most recent call last):",
msg="The exception message should NOT contain traceback information... "
Expand All @@ -213,7 +253,7 @@ def raise_exc(data, opts):
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_show_with_changelog_python_exc_in_cli_debug_mode(self):
def test_with_changelog_python_exc_in_cli_debug_mode(self):
w("""
cat <<EOF > .gitchangelog.rc
Expand All @@ -227,7 +267,7 @@ def raise_exc(data, opts):
""")

out, err, errlvl = cmd('$tprog --debug show')
out, err, errlvl = cmd('$tprog --debug')
self.assertContains(
err, "XYZ",
msg="The exception message should be displayed and thus contain XYZ... "
Expand All @@ -249,7 +289,7 @@ def raise_exc(data, opts):
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_show_with_changelog_python_exc_in_cli_debug_mode_after(self):
def test_show_with_changelog_python_exc_in_cli_debug_mode_deprecated(self):
w("""
cat <<EOF > .gitchangelog.rc
Expand All @@ -263,7 +303,7 @@ def raise_exc(data, opts):
""")

out, err, errlvl = cmd('$tprog show --debug')
out, err, errlvl = cmd('$tprog --debug show')
self.assertContains(
err, "XYZ",
msg="The exception message should be displayed and thus contain XYZ... "
Expand All @@ -272,6 +312,10 @@ def raise_exc(data, opts):
err, "--debug",
msg="Should not contain any message about ``--debug``... "
"Current stderr:\n%s" % err)
self.assertContains(
err, "deprecated",
msg="Should contain message about show being deprecated... "
"Current stderr:\n%s" % err)
self.assertContains(
err, "Traceback (most recent call last):",
msg="The exception message should contain traceback information... "
Expand All @@ -285,7 +329,7 @@ def raise_exc(data, opts):
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_show_with_changelog_python_exc_in_cli_debug_mode_default_arg(self):
def test_with_changelog_python_exc_in_cli_debug_mode_after(self):
w("""
cat <<EOF > .gitchangelog.rc
Expand All @@ -299,7 +343,7 @@ def raise_exc(data, opts):
""")

out, err, errlvl = cmd('$tprog --debug')
out, err, errlvl = cmd('$tprog HEAD --debug')
self.assertContains(
err, "XYZ",
msg="The exception message should be displayed and thus contain XYZ... "
Expand All @@ -321,7 +365,7 @@ def raise_exc(data, opts):
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_show_with_changelog_python_exc_in_env_debug_mode(self):
def test_show_with_changelog_python_exc_in_cli_debug_mode_after_deprecated(self):
w("""
cat <<EOF > .gitchangelog.rc
Expand All @@ -335,7 +379,7 @@ def raise_exc(data, opts):
""")

out, err, errlvl = cmd('DEBUG_GITCHANGELOG=1 $tprog show')
out, err, errlvl = cmd('$tprog show --debug')
self.assertContains(
err, "XYZ",
msg="The exception message should be displayed and thus contain XYZ... "
Expand All @@ -344,6 +388,10 @@ def raise_exc(data, opts):
err, "--debug",
msg="Should not contain any message about ``--debug``... "
"Current stderr:\n%s" % err)
self.assertContains(
err, "deprecated",
msg="Should contain message about show being deprecated... "
"Current stderr:\n%s" % err)
self.assertContains(
err, "Traceback (most recent call last):",
msg="The exception message should contain traceback information... "
Expand All @@ -357,7 +405,7 @@ def raise_exc(data, opts):
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_show_with_changelog_python_exc_in_env_debug_mode_default_arg(self):
def test_with_changelog_python_exc_in_env_debug_mode(self):
w("""
cat <<EOF > .gitchangelog.rc
Expand Down Expand Up @@ -393,8 +441,48 @@ def raise_exc(data, opts):
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_incremental_show_call(self):
out, err, errlvl = cmd('$tprog show 0.0.2..0.0.3')
def test_show_with_changelog_python_exc_in_env_debug_mode_deprecated(self):
w("""
cat <<EOF > .gitchangelog.rc
def raise_exc(data, opts):
raise Exception('Test Exception XYZ')
output_engine = raise_exc
EOF
""")

out, err, errlvl = cmd('DEBUG_GITCHANGELOG=1 $tprog show')
self.assertContains(
err, "XYZ",
msg="The exception message should be displayed and thus contain XYZ... "
"Current stderr:\n%s" % err)
self.assertNotContains(
err, "--debug",
msg="Should not contain any message about ``--debug``... "
"Current stderr:\n%s" % err)
self.assertContains(
err, "deprecated",
msg="Should contain message about show being deprecated... "
"Current stderr:\n%s" % err)
self.assertContains(
err, "Traceback (most recent call last):",
msg="The exception message should contain traceback information... "
"Current stderr:\n%s" % err)
self.assertEqual(
errlvl, 255,
msg="Should fail with errlvl 255 if exception in output_engine..."
"Current errlvl: %s" % errlvl)
self.assertEqual(
out, "",
msg="There should be no standard output. "
"Current stdout:\n%r" % out)

def test_incremental_call(self):
out, err, errlvl = cmd('$tprog 0.0.2..0.0.3')
self.assertEqual(
errlvl, 0,
msg="Should not fail on simple repo and without config file")
Expand All @@ -415,6 +503,28 @@ def test_incremental_show_call(self):
self.INCR_REFERENCE_002_003.split("\n"),
lineterm="")))

def test_incremental_show_call_deprecated(self):
out, err, errlvl = cmd('$tprog show 0.0.2..0.0.3')
self.assertEqual(
errlvl, 0,
msg="Should not fail on simple repo and without config file")
self.assertContains(
err, "deprecated",
msg="There should be a deprecated warning. "
"Current stderr:\n%r" % err)
self.assertContains(
out, "0.0.3",
msg="The tag 0.0.3 should be displayed in stdout... "
"Current stdout:\n%s" % out)
self.assertEqual(
out, self.INCR_REFERENCE_002_003,
msg="Should match our reference output... "
"diff of changelogs:\n%s"
% '\n'.join(difflib.unified_diff(
out.split("\n"),
self.INCR_REFERENCE_002_003.split("\n"),
lineterm="")))

def test_overriding_options(self):
"""We must be able to define a small gitchangelog.rc that adjust only
one variable of all the builtin defaults."""
Expand Down Expand Up @@ -570,7 +680,7 @@ def test_same_output_with_different_engine_incr(self):
EOF
""")
changelog = w('$tprog show 0.0.2..0.0.3')
changelog = w('$tprog 0.0.2..0.0.3')
self.assertEqual(
changelog, self.INCR_REFERENCE_002_003,
msg="Mustache output should match our reference output... "
Expand All @@ -585,7 +695,7 @@ def test_same_output_with_different_engine_incr(self):
EOF
""")
changelog = w('$tprog show 0.0.2..0.0.3')
changelog = w('$tprog 0.0.2..0.0.3')
self.assertEqual(
changelog, self.INCR_REFERENCE_002_003,
msg="Mako output should match our reference output... "
Expand Down
2 changes: 1 addition & 1 deletion test/test_issue61.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_command_line_overrights_config(self):



out, err, errlvl = cmd('$tprog show HEAD')
out, err, errlvl = cmd('$tprog HEAD')
self.assertEqual(
err, "",
msg="There should be non error messages. "
Expand Down

0 comments on commit ce9843a

Please sign in to comment.