Skip to content

Commit

Permalink
Append date cli option added (#8).
Browse files Browse the repository at this point in the history
  • Loading branch information
offa committed Jun 11, 2020
1 parent 602c918 commit 34eb9c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions test/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import unittest
from trackpack import cli


class TestCli(unittest.TestCase):

def test_prints_help_if_no_arguments_passed(self):
Expand All @@ -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)
2 changes: 1 addition & 1 deletion trackpack/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions trackpack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

0 comments on commit 34eb9c0

Please sign in to comment.