diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 9263e21..90b9b25 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -1,5 +1,9 @@ = PopPage Changelog +== poppage-0.6.4 (2017-11-04) +=== Added + - Can now pass in DFLTFILE as a single argument, command will be read from the file. + == poppage-0.6.3 (2017-11-01) === Fixed - Fixes issue with incorrect implicit OUTPATH when one is not provided. diff --git a/app/poppage.py b/app/poppage.py index 3cf807e..03755de 100644 --- a/app/poppage.py +++ b/app/poppage.py @@ -1,6 +1,7 @@ """PopPage is a utility for generating output from templates. Usage: + poppage INPATH poppage make [options] [(--string KEY VAL) | (--file KEY PATH)]... poppage check [options] poppage run [options] [(--string KEY VAL) | (--file KEY PATH)]... @@ -80,7 +81,7 @@ ##==============================================================# #: Application version string. -__version__ = "0.6.3" +__version__ = "0.6.4" #: Key separator. KEYSEP = "::" @@ -209,6 +210,8 @@ def render_file(tmplpath, tmpldict): def make(inpath, tmpldict, outpath=None, **kwargs): """Generates a file or directory based on the given input template/dictionary.""" + if not outpath: + outpath = os.getcwd() if op.isfile(inpath): return make_file(inpath, tmpldict, outpath=outpath) else: @@ -295,7 +298,7 @@ def check(inpath, echo=False, **kwargs): def run(inpath, tmpldict, outpath=None, execute=None): """Handles logic for `run` command.""" if not outpath: - outpath = "__temp-poppage-" + _getrands(6) + outpath = op.join(os.getcwd(), "__temp-poppage-" + _getrands(6)) make(inpath, tmpldict, outpath=outpath) qprompt.hrule() if not execute: @@ -321,13 +324,13 @@ def main(): exit_err("Must supply INPATH!") # Handle command. - if args['check']: + if utildict['command'] == "check": check(utildict['inpath'], echo=True) - elif args['make']: + elif utildict['command'] == "make": make(utildict['inpath'], tmpldict, outpath=utildict['outpath']) - elif args['run']: + elif utildict['command'] == "run": run(utildict['inpath'], tmpldict, outpath=utildict['outpath'], execute=utildict['execute']) - elif args['debug']: + elif utildict['command'] == "debug": qprompt.echo("Utility Dictionary:") pprint(utildict) qprompt.echo("Template Dictionary:") diff --git a/app/setup.py b/app/setup.py index c3e6116..fe93cf8 100644 --- a/app/setup.py +++ b/app/setup.py @@ -22,7 +22,7 @@ setup( name = "poppage", - version = "0.6.3", + version = "0.6.4", author = "Jeff Rimko", author_email = "jeffrimko@gmail.com", description = "Utility for generating files and directories from templates.", diff --git a/app/utilconf.py b/app/utilconf.py index 03e4a9a..a552d27 100644 --- a/app/utilconf.py +++ b/app/utilconf.py @@ -117,12 +117,15 @@ def get_cliopts(args): val = args.get("--" + key) if val: opts[key] = val + cmd = [c for c in ['check','debug','make','run'] if args.get(c)] + if cmd: + opts['command'] = cmd[0] return opts def get_defopts(dfltdict): opts = {} if "__opt__" in dfltdict.keys(): - for key in ['execute', 'outpath']: + for key in ['execute', 'outpath', 'command']: opts[key] = (dfltdict.get('__opt__', {}) or {}).get(key) for key in ['inpath']: # Make paths absolute based on the location of the defaults file. @@ -147,7 +150,8 @@ def get_tmpldict(args): if dfltfile: global _DFLTFILE _DFLTFILE = op.abspath(dfltfile) - tmpldict = yaml.load(fsys.File(dfltfile).read()) + data = fsys.File(dfltfile).read() + tmpldict = yaml.load(data) tmpldict = update(tmpldict, {k:v for k,v in zip(args['--string'], args['VAL'])}) tmpldict = update(tmpldict, {k:fsys.File(v).read().strip() for k,v in zip(args['--file'], args['PATH'])}) @@ -174,11 +178,14 @@ def get_tmpldict(args): def parse(args): """Parses the given arguments into a template dictionary.""" + if args.get('INPATH'): + args['--defaults'] = args['INPATH'] + if not op.isfile(args['--defaults']): + from poppage import exit_err + exit_err("Given path could not be found: `%s`" % (args['--defaults'])) tmpldict = get_tmpldict(args) utildict = get_defopts(tmpldict) utildict.update(get_cliopts(args)) - if not utildict.get('outpath'): - utildict['outpath'] = os.getcwd() return utildict, tmpldict ##==============================================================# diff --git a/tests/cli_test_1.py b/tests/cli_test_1.py index 99adb04..e0ea242 100644 --- a/tests/cli_test_1.py +++ b/tests/cli_test_1.py @@ -106,6 +106,15 @@ def test_cli_14(test): test.assertTrue(op.isfile("./foo/bar.txt")) test.assertEqual(File("./foo/bar.txt").read(), "hello baz!") + def test_cli_15(test): + """Check for basic make CLI functionality with defaults.""" + with Cwd("__output__"): + retval = call("../defaults/d7.yaml", app_path="../../app") + test.assertEqual(0, retval) + test.assertTrue(op.isdir("./foo")) + test.assertTrue(op.isfile("./foo/bar.txt")) + test.assertEqual(File("./foo/bar.txt").read(), "hello baz!") + ##==============================================================# ## SECTION: Main Body # ##==============================================================# diff --git a/tests/defaults/d7.yaml b/tests/defaults/d7.yaml index 051f2e6..9fbe484 100644 --- a/tests/defaults/d7.yaml +++ b/tests/defaults/d7.yaml @@ -1,4 +1,5 @@ __opt__: + command: make inpath: ../templates/{{mydir}} mydir: foo myfile: bar