diff options
author | Daniel Silverstone <dsilvers+gitlab@digital-scurf.org> | 2021-04-12 15:45:30 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers+gitlab@digital-scurf.org> | 2021-04-12 15:45:30 +0000 |
commit | 08740caf6595d3d69458d8196bd489440d508289 (patch) | |
tree | 1a93124beae03e9114af44d2849eb5aebf663010 | |
parent | 0bac83375568e399f2bc3281c1bfc7c43c7a662f (diff) | |
parent | 71d60540f441304f5010fd42284a0c70f9b36af9 (diff) | |
download | subplot-08740caf6595d3d69458d8196bd489440d508289.tar.gz |
Merge branch 'runcmd_cwd' into 'main'
feat(python lib/runcmd): run commands in sub-directory
Closes #175
See merge request larswirzenius/subplot!146
-rw-r--r-- | share/python/lib/runcmd.md | 20 | ||||
-rw-r--r-- | share/python/lib/runcmd.py | 11 | ||||
-rw-r--r-- | share/python/lib/runcmd.yaml | 8 |
3 files changed, 38 insertions, 1 deletions
diff --git a/share/python/lib/runcmd.md b/share/python/lib/runcmd.md index 4615f69..5f99b2a 100644 --- a/share/python/lib/runcmd.md +++ b/share/python/lib/runcmd.md @@ -37,6 +37,16 @@ then exit code is 0 and command is successful ~~~ +## Successful execution in a sub-directory + +~~~scenario +given a directory xyzzy +when I run, in xyzzy, /bin/pwd +then exit code is 0 +then command is successful +then stdout contains "/xyzzy" +~~~ + ## Failed execution ~~~scenario @@ -45,6 +55,15 @@ then exit code is not 0 and command fails ~~~ +## Failed execution in a sub-directory + +~~~scenario +given a directory xyzzy +when I try to run, in xyzzy, /bin/false +then exit code is not 0 +and command fails +~~~ + # Check we can prepend to $PATH This scenario verifies that we can add a directory to the beginning of @@ -187,6 +206,7 @@ template: python bindings: - runcmd.yaml - runcmd_test.yaml +- files.yaml functions: - runcmd.py - runcmd_test.py diff --git a/share/python/lib/runcmd.py b/share/python/lib/runcmd.py index a2564c6..cc4fd38 100644 --- a/share/python/lib/runcmd.py +++ b/share/python/lib/runcmd.py @@ -113,9 +113,18 @@ def runcmd_step(ctx, argv0=None, args=None): runcmd_exit_code_is_zero(ctx) +def runcmd_step_in(ctx, dirname=None, argv0=None, args=None): + runcmd_try_to_run_in(ctx, dirname=dirname, argv0=argv0, args=args) + runcmd_exit_code_is_zero(ctx) + + def runcmd_try_to_run(ctx, argv0=None, args=None): + runcmd_try_to_run_in(ctx, dirname=None, argv0=argv0, args=args) + + +def runcmd_try_to_run_in(ctx, dirname=None, argv0=None, args=None): argv = [shlex.quote(argv0)] + shlex.split(args) - runcmd_run(ctx, argv) + runcmd_run(ctx, argv, cwd=dirname) # diff --git a/share/python/lib/runcmd.yaml b/share/python/lib/runcmd.yaml index 48dde90..a5119d8 100644 --- a/share/python/lib/runcmd.yaml +++ b/share/python/lib/runcmd.yaml @@ -10,10 +10,18 @@ regex: true function: runcmd_step +- when: I run, in (?P<dirname>\S+), (?P<argv0>\S+)(?P<args>.*) + regex: true + function: runcmd_step_in + - when: I try to run (?P<argv0>\S+)(?P<args>.*) regex: true function: runcmd_try_to_run +- when: I try to run, in (?P<dirname>\S+), (?P<argv0>\S+)(?P<args>.*) + regex: true + function: runcmd_try_to_run_in + # Steps to examine exit code of latest command. - then: exit code is {exit} |