Skip to content

Commit c953a46

Browse files
committed
Make docopt library version available as a variable for sourcing
1 parent fa859b9 commit c953a46

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

README.adoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ automatically glean the previously used parameters from your script and re-apply
264264
them.
265265

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

269270
On every invocation docopt checks that the library version and the version of
270271
the dynamic part in the script match. The parser exits with an error if that is

docopt_sh/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def generate(self, script):
4848
)
4949

5050
if self.parameters.library_path:
51-
library = indent(f'''source {self.parameters.library_path} '{__version__}' || {{
51+
library = indent(f'''local v='{__version__}'; source {self.parameters.library_path} "$v" || {{
5252
ret=$?
5353
printf -- "exit %d\\n" "$ret"
5454
exit "$ret"

tests/test_scriptpatching.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_library_version(monkeypatch, capsys, bash):
224224
invoke_docopt(monkeypatch, program_params=['--library', library.name, script.name])
225225
with open(script.name, 'r') as h:
226226
contents = h.read()
227-
contents = re.sub(r"source (\S+) '([^']+)'", r"source \1 '0.0.0'", contents)
227+
contents = re.sub(r'source (\S+) "([^"]+)"', r"source \1 '0.0.0'", contents)
228228
with open(script.name, 'w') as h:
229229
h.write(contents)
230230
code, out, err = run(bash, 'ship', 'new', 'Olympia')

0 commit comments

Comments
 (0)