I'm trying to implement a command which involves sending POST/GET
request to a remote server and interpret JSON
format result. Since it's quite hard to parse JSON via bash
, I decide to write python script first and call it within the shell script.
My shell script now looks like this
#!/bin/sh
case $1 in
submit-job)
python3 src/submit-job.py
;;
lists-job)
python3 src/lists-job.py
;;
....and so on
esac
I hope my users can use this command as following.
Job submit-job argument1 argument2...
Job lists-job
...and so on
Basically. I have only 1 Python class file called Job.py
including multiple functions like submit-job
and lists-job
.
However, in order to separate different functions to a different command argument, I have to create seperate python files to trigger it. (Like submit-job.py
and lists-job.py
).
For example. submit-job.py
from Job import Job
j = Job()
j.submit_job()
lists-job.py
from Job import Job
j = Job()
j.lists_job()
As you can see, they are quite similar. Is there a better way or best practice to achieve what I want?