Skip to content

Commit

Permalink
Make docopt library version available as a variable for sourcing
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed May 28, 2024
1 parent fa859b9 commit c953a46
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ automatically glean the previously used parameters from your script and re-apply
them.

`--library` can be any valid bash expression, meaning you can use things like
`"$(dirname "$0")"`.
`"$(dirname "$0")/docopt-lib-$v.sh"` (the `$v` is the version of docopt
the parser AST was generated with).

On every invocation docopt checks that the library version and the version of
the dynamic part in the script match. The parser exits with an error if that is
Expand Down
2 changes: 1 addition & 1 deletion docopt_sh/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def generate(self, script):
)

if self.parameters.library_path:
library = indent(f'''source {self.parameters.library_path} '{__version__}' || {{
library = indent(f'''local v='{__version__}'; source {self.parameters.library_path} "$v" || {{
ret=$?
printf -- "exit %d\\n" "$ret"
exit "$ret"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scriptpatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_library_version(monkeypatch, capsys, bash):
invoke_docopt(monkeypatch, program_params=['--library', library.name, script.name])
with open(script.name, 'r') as h:
contents = h.read()
contents = re.sub(r"source (\S+) '([^']+)'", r"source \1 '0.0.0'", contents)
contents = re.sub(r'source (\S+) "([^"]+)"', r"source \1 '0.0.0'", contents)
with open(script.name, 'w') as h:
h.write(contents)
code, out, err = run(bash, 'ship', 'new', 'Olympia')
Expand Down

0 comments on commit c953a46

Please sign in to comment.