What is the "cleanest" way to implement an command-line UI, similar to git's, for example:
git push origin/master
git remote add origin git://example.com master
Ideally also allowing the more flexible parsing, for example,
jump_to_folder app theappname v2
jump_to_folder app theappname source
jump_to_folder app theappname source v2
jump_to_folder app theappname build v1
jump_to_folder app theappname build 1
jump_to_folder app theappname v2 build
jump_to_folder
is the scripts name, app
is the command, theappname
is a "fixed-location" parameter, "build" and "v2" etc are arguments (For example, possible arguments would be any number/any number prefixed with a v, or build/source/tmp/config)
I could just manually parse the arguments with a series of if
/else
/elifs
, but there must be a more elegant way to do this?
As an entirely theoretically example, I could describe the UI schema..
app:
fixed: application_name
optional params:
arg subsection:
"build"
"source"
"tmp"
"config"
arg version:
integer
"v" + integer
Then parse the supplied arguments though the above schema, and get a dictionary:
>>> print schema.parse(["app", "theappname", "v1", "source"])
{
"application_name": "theappname",
"params":{
"subsection": "source",
"version":"v1"
}
}
Does such a system exist? If not, how would I go about implementing something along these lines?