I was just able to make it work with DVC, still unsure if recursing through ArgumentParser is correct here (consider this as a WIP for now, more testing is required).
You can try it out with dvc. Closes #33.
Example output for dvc metrics
```sh
#compdef dvc
# AUTOMATCALLY GENERATED by `shtab`
_shtab_dvc() {
local context state line curcontext="$curcontext"
_arguments -C $_shtab_dvc_options \
': :_shtab_dvc_commands' \
'*::: :->dvc'
case $state in
dvc)
words=($line[1] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:_shtab_dvc-$line[1]:"
case $line[1] in
metrics) _shtab_dvc_metrics ;;
params) _shtab_dvc_params ;;
plots) _shtab_dvc_plots ;;
esac
esac
}
_shtab_dvc_metrics() {
local context state line curcontext="$curcontext"
_arguments -C $_shtab_dvc_metrics_options \
': :_shtab_dvc_metrics_commands' \
'*::: :->metrics'
case $state in
metrics)
words=($line[1] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:_shtab_dvc_metrics-$line[1]:"
case $line[1] in
diff) _arguments -C $_shtab_dvc_metrics_diff_options ;;
show) _arguments -C $_shtab_dvc_metrics_show_options ;;
esac
esac
}
_shtab_dvc_commands() {
local _commands=(
"metrics:Commands to display and compare metrics."
"params:Commands to display params."
"plots:Commands to visualize and compare plot metrics in structured files (JSON, YAML, CSV, TSV)."
)
_describe 'dvc commands' _commands
}
_shtab_dvc_metrics_commands() {
local _commands=(
"diff:Show changes in metrics between commits in the DVC repository, or between a commit and the workspace."
"show:Print metrics, with optional formatting."
)
_describe 'dvc metrics commands' _commands
}
_shtab_dvc_options=(
"*"{-q,--quiet}"[Be quiet.]"
"*"{-v,--verbose}"[Be verbose.]"
"(- :)"{-h,--help}"[Show this help message and exit.]"
{-V,--version}"[Show program\'s version.]:version:"
"--cd[Change to directory before executing.]:cd:"
)
_shtab_dvc_metrics_options=(
"(- :)"{-h,--help}"[show this help message and exit]"
"*"{-q,--quiet}"[Be quiet.]"
"*"{-v,--verbose}"[Be verbose.]"
)
_shtab_dvc_metrics_diff_options=(
"(- :)"{-h,--help}"[show this help message and exit]"
"*"{-q,--quiet}"[Be quiet.]"
"*"{-v,--verbose}"[Be verbose.]"
"--targets[Specific metrics file(s) to compare (even if not found as \`metrics\` in \`dvc.yaml\`). Using -R, directories to search metrics files in can also be given.Shows all tracked metrics by default.]:targets:_files"
{-R,--recursive}"[If any target is a directory, recursively search and process metrics files.]"
"--all[Show unchanged metrics as well.]"
{--json,--show-json}"[Show output in JSON format.]"
{--md,--show-md}"[Show tabulated output in the Markdown format (GFM).]"
"--no-path[Don\'t show metric path.]"
"--precision[Round metrics to \`n\` digits precision after the decimal point. Rounds to 5 digits by default.]:precision:"
":Old Git commit to compare (defaults to HEAD):"
":New Git commit to compare (defaults to the current workspace):"
)
_shtab_dvc_metrics_show_options=(
"(- :)"{-h,--help}"[show this help message and exit]"
"*"{-q,--quiet}"[Be quiet.]"
"*"{-v,--verbose}"[Be verbose.]"
{-a,--all-branches}"[Show metrics for all branches.]"
{-T,--all-tags}"[Show metrics for all tags.]"
{-A,--all-commits}"[Show metrics for all commits.]"
{--json,--show-json}"[Show output in JSON format.]"
{--md,--show-md}"[Show tabulated output in the Markdown format (GFM).]"
{-R,--recursive}"[If any target is a directory, recursively search and process metrics files.]"
"--precision[Round metrics to \`n\` digits precision after the decimal point. Rounds to 5 digits by default.]:precision:"
"(*)::Limit command scope to these metrics files. Using -R, directories to search metrics files in can also be given.:_files"
)
# Custom Preamble
# End Custom Preamble
typeset -A opt_args
_shtab_dvc "$@"
```
I was just able to make it work with DVC, still unsure if recursing through ArgumentParser is correct here (consider this as a WIP for now, more testing is required).
You can try it out with
dvc
. Closes #33.Example output for
```sh #compdef dvc # AUTOMATCALLY GENERATED by `shtab` _shtab_dvc() { local context state line curcontext="$curcontext" _arguments -C $_shtab_dvc_options \ ': :_shtab_dvc_commands' \ '*::: :->dvc' case $state in dvc) words=($line[1] "${words[@]}") (( CURRENT += 1 )) curcontext="${curcontext%:*:*}:_shtab_dvc-$line[1]:" case $line[1] in metrics) _shtab_dvc_metrics ;; params) _shtab_dvc_params ;; plots) _shtab_dvc_plots ;; esac esac } _shtab_dvc_metrics() { local context state line curcontext="$curcontext" _arguments -C $_shtab_dvc_metrics_options \ ': :_shtab_dvc_metrics_commands' \ '*::: :->metrics' case $state in metrics) words=($line[1] "${words[@]}") (( CURRENT += 1 )) curcontext="${curcontext%:*:*}:_shtab_dvc_metrics-$line[1]:" case $line[1] in diff) _arguments -C $_shtab_dvc_metrics_diff_options ;; show) _arguments -C $_shtab_dvc_metrics_show_options ;; esac esac } _shtab_dvc_commands() { local _commands=( "metrics:Commands to display and compare metrics." "params:Commands to display params." "plots:Commands to visualize and compare plot metrics in structured files (JSON, YAML, CSV, TSV)." ) _describe 'dvc commands' _commands } _shtab_dvc_metrics_commands() { local _commands=( "diff:Show changes in metrics between commits in the DVC repository, or between a commit and the workspace." "show:Print metrics, with optional formatting." ) _describe 'dvc metrics commands' _commands } _shtab_dvc_options=( "*"{-q,--quiet}"[Be quiet.]" "*"{-v,--verbose}"[Be verbose.]" "(- :)"{-h,--help}"[Show this help message and exit.]" {-V,--version}"[Show program\'s version.]:version:" "--cd[Change to directory before executing.]:cd:" ) _shtab_dvc_metrics_options=( "(- :)"{-h,--help}"[show this help message and exit]" "*"{-q,--quiet}"[Be quiet.]" "*"{-v,--verbose}"[Be verbose.]" ) _shtab_dvc_metrics_diff_options=( "(- :)"{-h,--help}"[show this help message and exit]" "*"{-q,--quiet}"[Be quiet.]" "*"{-v,--verbose}"[Be verbose.]" "--targets[Specific metrics file(s) to compare (even if not found as \`metrics\` in \`dvc.yaml\`). Using -R, directories to search metrics files in can also be given.Shows all tracked metrics by default.]:targets:_files" {-R,--recursive}"[If any target is a directory, recursively search and process metrics files.]" "--all[Show unchanged metrics as well.]" {--json,--show-json}"[Show output in JSON format.]" {--md,--show-md}"[Show tabulated output in the Markdown format (GFM).]" "--no-path[Don\'t show metric path.]" "--precision[Round metrics to \`n\` digits precision after the decimal point. Rounds to 5 digits by default.]:precision:" ":Old Git commit to compare (defaults to HEAD):" ":New Git commit to compare (defaults to the current workspace):" ) _shtab_dvc_metrics_show_options=( "(- :)"{-h,--help}"[show this help message and exit]" "*"{-q,--quiet}"[Be quiet.]" "*"{-v,--verbose}"[Be verbose.]" {-a,--all-branches}"[Show metrics for all branches.]" {-T,--all-tags}"[Show metrics for all tags.]" {-A,--all-commits}"[Show metrics for all commits.]" {--json,--show-json}"[Show output in JSON format.]" {--md,--show-md}"[Show tabulated output in the Markdown format (GFM).]" {-R,--recursive}"[If any target is a directory, recursively search and process metrics files.]" "--precision[Round metrics to \`n\` digits precision after the decimal point. Rounds to 5 digits by default.]:precision:" "(*)::Limit command scope to these metrics files. Using -R, directories to search metrics files in can also be given.:_files" ) # Custom Preamble # End Custom Preamble typeset -A opt_args _shtab_dvc "$@" ```dvc metrics