567bd593954641bd59376f6fd5f9c06bf37bc9e7

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

refactor(cli): use self-referencing in subcommand functions

Diff

This diff is truncated to protect this page.

  1diff --git a/lib/cli.zsh b/lib/cli.zsh
  2index ec59d1d44fb502c56da20adca40a28c5b3694289..70076bcfb32c43c7acdcd75df95d582e12052902 100644
  3--- a/lib/cli.zsh
  4+++ b/lib/cli.zsh
  5@@ -182,7 +182,7 @@ function _omz::changelog {
  6     ! command git rev-parse --verify "${version}^{commit}"
  7   ) &>/dev/null; then
  8     cat >&2 <<EOF
  9-Usage: omz changelog [version]
 10+Usage: ${(j: :)${(s.::.)0#_}} [version]
 11 
 12 NOTE: <version> must be a valid branch, tag or commit.
 13 EOF
 14@@ -193,9 +193,9 @@ EOF
 15 }
 16 
 17 function _omz::plugin {
 18-  (( $# > 0 && $+functions[_omz::plugin::$1] )) || {
 19+  (( $# > 0 && $+functions[$0::$1] )) || {
 20     cat >&2 <<EOF
 21-Usage: omz plugin <command> [options]
 22+Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
 23 
 24 Available commands:
 25 
 26@@ -212,12 +212,12 @@ EOF
 27   local command="$1"
 28   shift
 29 
 30-  _omz::plugin::$command "$@"
 31+  $0::$command "$@"
 32 }
 33 
 34 function _omz::plugin::disable {
 35   if [[ -z "$1" ]]; then
 36-    echo >&2 "Usage: omz plugin disable <plugin> [...]"
 37+    echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
 38     return 1
 39   fi
 40 
 41@@ -307,7 +307,7 @@ multi == 1 && length(\$0) > 0 {
 42 
 43 function _omz::plugin::enable {
 44   if [[ -z "$1" ]]; then
 45-    echo >&2 "Usage: omz plugin enable <plugin> [...]"
 46+    echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
 47     return 1
 48   fi
 49 
 50@@ -383,7 +383,7 @@ multi == 1 && /^[^#]*\)/ {
 51 
 52 function _omz::plugin::info {
 53   if [[ -z "$1" ]]; then
 54-    echo >&2 "Usage: omz plugin info <plugin>"
 55+    echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin>"
 56     return 1
 57   fi
 58 
 59@@ -430,7 +430,7 @@ function _omz::plugin::list {
 60 
 61 function _omz::plugin::load {
 62   if [[ -z "$1" ]]; then
 63-    echo >&2 "Usage: omz plugin load <plugin> [...]"
 64+    echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
 65     return 1
 66   fi
 67 
 68@@ -477,9 +477,9 @@ function _omz::plugin::load {
 69 }
 70 
 71 function _omz::pr {
 72-  (( $# > 0 && $+functions[_omz::pr::$1] )) || {
 73+  (( $# > 0 && $+functions[$0::$1] )) || {
 74     cat >&2 <<EOF
 75-Usage: omz pr <command> [options]
 76+Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
 77 
 78 Available commands:
 79 
 80@@ -493,7 +493,7 @@ EOF
 81   local command="$1"
 82   shift
 83 
 84-  _omz::pr::$command "$@"
 85+  $0::$command "$@"
 86 }
 87 
 88 function _omz::pr::clean {
 89@@ -534,7 +534,7 @@ function _omz::pr::test {
 90 
 91   # Check the input
 92   if ! [[ -n "$1" && "$1" =~ ^[[:digit:]]+$ ]]; then
 93-    echo >&2 "Usage: omz pr test <PR_NUMBER_or_URL>"
 94+    echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <PR_NUMBER_or_URL>"
 95     return 1
 96   fi
 97 
 98@@ -619,9 +619,9 @@ function _omz::reload {
 99 }
100 
101 function _omz::theme {
102-  (( $# > 0 && $+functions[_omz::theme::$1] )) || {
103+  (( $# > 0 && $+functions[$0::$1] )) || {
104     cat >&2 <<EOF