Automatically create python wrappers for bash script using docopts
See original GitHub issueHi,
I have a set of bash script that are now using docopts. I would like to be able to automatically create python function able to call these bash script.
The idea is the following one. I have a script test.sh with
Usage:
test.sh (-testdir <testDirPath>) [-v=<VERSION>]
test.sh -h | --help
Options:
-h --help Show this screen.
-testdir <path> Dew test directory path.
-v <version> Version for XX TOOL [default: Prod].
From which I can extract the Usage
part with grep/sed. Now I want to use docopt to automatically write a python script containing:
def test(testdir, v='Prod'):
subprocess.Popen(['test.sh.sh -testdir %s -v %s' %(testDir, v], shell = True).
It seems to be possible to get the arguments from docopt:
arguments = docopt(__doc__, version='Naval Fate 2.0')
print(arguments)
but how can I override docopt so it does not try parsing the current python script being executed as what I want is only the arguments dictionnary to buid the function test().
from docopt import docopt
with open ("test.doc", "r") as myfile:
data=myfile.read()
print(data)
arguments = docopt(data)
Any idea? Is this thing have been done before?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
docopts/README.md at master - GitHub
docopts : the command line wrapper for bash. Most concepts are documented in the docopt (without S) manual - see docopt.org. Many examples...
Read more >Building Beautiful Command Line Interfaces with Python
Docopt. Docopt is a lightweight python package for creating command line interface easily by parsing POSIC-style or Markdown usage instructions.
Read more >Release 2.10.0 Matˇej Týˇc - Argbash documentation
Argbash (https://argbash.dev) is a bash code generator that can assist you in writing scripts that accept arguments.
Read more >Wrapping bash scripts in python - Stack Overflow
this script will first create a temp file, then put shell commands in it, and give it execute permissions. and finally run the...
Read more >Build a Python Directory Tree Generator for the Command Line
tree.py provides an entry-point script for you to run the application. Then you have the rptree/ directory that holds a Python package with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If I understand it correctly: you want to access the internal data that been parsed and matched by docopt.
In short: nuh, docopt does not expose such api. May considering copy/paste and modify code from docopt.
My lib allows to access parsed data tree (and the matched status, errors, etc), but, I wont suggested it, as it’s really nested and complex without document/guid of this part
Nope, because in your example, the args are provided and hard coded. What I want is being able to get the dictionnary with typed arguments; default values and so on in order to write (generate) a python wrapper file that defines python function with the correct set of arguments that I can use in python only.
I can write all the wrapping function myself, by hand but it will request eacht time a manual modifiction if my bash function changes.