-
I am making a cli tool in which it would make more sense to have the optional argument followed by a requirement. It's an alias manager, so I want to do something like
In the above example, the required argument is the path (you need a path to cd to). The Because I store the entry as
I don't think this is currently supported when I look at the Current workaround |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
No, this is not supported, but there is an elegant solution if you are willing to consider a different (and more common) usage pattern. Using optional positional arguments before required positional arguments (i.e. Now, if I understand you correctly, you want to accomplish this:
I would like to propose the following target usage: # Running
$ tmt run myalias # run myalias
$ tmt myalias # same, invoking the `run` command implicitly
# Adding
$ tmt add /path # add path using a default (indexed) alias
$ tmt add --alias myalias /path # add path using a specific alias
$ tmt add /path --alias myalias # same, order doesn't matter
$ tmt a /path # using the `add` command alias If this (or similar) usage is acceptable, it can be done using the Here is a sample name: tmt
help: Alias manager
version: 0.1.0
commands:
- name: run
help: Run an alias
default: force # Makes any unrecognized input to be passed to this command
args:
- name: alias
required: true
help: Alias to run
- name: add
alias: a
help: Add an alias
args:
- name: path
required: true
help: Path to add
flags:
- long: --alias
short: -a
arg: name
help: Alias to use
examples:
- tmt add /some/path
- tmt add --alias dev /some/path |
Beta Was this translation helpful? Give feedback.
No, this is not supported, but there is an elegant solution if you are willing to consider a different (and more common) usage pattern.
Using optional positional arguments before required positional arguments (i.e.
mycli [ALIAS] PATH
is bad form in my opinion.I do not know of any command line utility that does that, and if there is, it is a very small minority. Using such a syntax requires counting the arguments to determine if the first one is ALIAS or PATH.
Now, if I understand you correctly, you want to accomplish this:
tmt ALIAS
run something that is associated with the alias