From 34eb9c01742851ae692b9e6cbf6ef3c04c181c6d Mon Sep 17 00:00:00 2001 From: offa Date: Thu, 11 Jun 2020 17:06:16 +0200 Subject: [PATCH] Append date cli option added (#8). --- test/cli_test.py | 6 ++++++ trackpack/__main__.py | 2 +- trackpack/cli.py | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/cli_test.py b/test/cli_test.py index ac730bd..409e7a6 100644 --- a/test/cli_test.py +++ b/test/cli_test.py @@ -18,6 +18,7 @@ import unittest from trackpack import cli + class TestCli(unittest.TestCase): def test_prints_help_if_no_arguments_passed(self): @@ -39,3 +40,8 @@ def test_pack_with_custom_archive_name(self): args = cli.parse_args(['pack', "--name", "xyz"]) self.assertEqual("pack", args.command) self.assertEqual("xyz", args.archive_name) + + def test_pack_with_date(self): + args = cli.parse_args(['pack', "--append-date"]) + self.assertEqual("pack", args.command) + self.assertTrue(args.append_date) diff --git a/trackpack/__main__.py b/trackpack/__main__.py index 0bc3bd9..f4f039e 100644 --- a/trackpack/__main__.py +++ b/trackpack/__main__.py @@ -42,7 +42,7 @@ def main(): if archive_name.endswith(".zip"): archive_name = args.archive_name[:-4] - if config.get("append_date", False): + if args.append_date or config.get("append_date", False): archive_name = "-".join((archive_name, date.today().strftime('%Y-%m-%d'))) (_, stems) = trackpacker.discover_audiofiles(project_name, export_dir, diff --git a/trackpack/cli.py b/trackpack/cli.py index 3db620f..567259b 100644 --- a/trackpack/cli.py +++ b/trackpack/cli.py @@ -17,11 +17,14 @@ import argparse + def parse_args(args): parser = argparse.ArgumentParser(prog="trackpack", description='Audio tracks packaging') subparsers = parser.add_subparsers(dest="command") pack_parser = subparsers.add_parser("pack", help="Pack audio files") pack_parser.add_argument("pack_explicit_files", metavar="file", nargs="*", help="Files to pack") pack_parser.add_argument("--name", dest="archive_name", type=str, help="Archive name") + pack_parser.add_argument("--append-date", dest="append_date", action="store_true", + help="Append date to archive name") return parser.parse_args(args=args if args else ['--help'])