Skip to content

Instantly share code, notes, and snippets.

@dalang
Last active December 22, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalang/6403070 to your computer and use it in GitHub Desktop.
Save dalang/6403070 to your computer and use it in GitHub Desktop.
oh-my-zsh razor plugin

#oh-my-zsh razor plugin Enable Razor from puppetlabs capability of command autocomplete

Ensure you have installed oh-my-zsh ###How to use this razor plugin:

  1. mkdir a new folder named razor in your oh-my-zsh plugin folder: ~/.oh-my-zsh/plugins/razor
  2. put this file in ~/.oh-my-zsh/plugins/razor
  3. config your ~/.zshrc to enable razor plugin: add razor in the bracket of the line starts with plugins=(
  4. Try type razor in terminal and test command autocomplete with tab
#compdef razor
#autoload
local -a _1st_arguments
_1st_arguments=(
'active_model:sed to view active models or active model logs, and to remove active models.'
'bmc:used to view the current list of BMCs; also used by to register new BMCs with Razor.'
'broker:used to add, view, update, and remove Broker Targets.'
'image:used to add, view, and remove Images.'
'log:used to view logs'
'model:used to add, view, update, and remove models.'
'node:used to view the current list of nodes (or node details)'
'policy:used to view, create, update, and remove policies.'
'tag:used to view, create, update, and remove tags.'
'vmodel:used to add, view, update, and remove vmodels.'
)
local -a _active_model_arguments
_active_model_arguments=(
'get:View active models'
'serial:View specific active model by serial number'
'logview:Prints an aggregate active model log view'
'remove:Remove existing (or all) active model(s)'
)
local -a _image_arguments
_image_arguments=(
'get:View images'
'add:Add a new image to the system'
'remove:Remove existing image from the system'
)
local -a _model_arguments
_model_arguments=(
'get:View model'
'add:Create a new model instance'
'update:Update a specific model instance'
'remove:Remove existing model(s)'
)
local -a _node_arguments
_node_arguments=(
'get:View node'
)
local -a _policy_arguments
_policy_arguments=(
'get:View available policy templates'
'add:Create a new policy'
'update:Update an existing policy'
'remove:Remove existing policy(s)'
'callback:Invoke a callback for an existing policy(s)'
'vcallback:Invoke a vmodel callback for an existing policy(s)'
)
local -a _tag_arguments
_tag_arguments=(
'get:View details of a Tag'
'add:Create a new Tag'
'update:Update an existing Tag'
'remove:Remove existing Tag(s)'
'matcher:Tag Matcher'
)
local -a _vmodel_arguments
_vmodel_arguments=(
'get:View vmodel'
'add:Create a new vmodel instance'
'update:Update a specific vmodel instance'
'remove:Remove existing vmodel(s)'
)
local expl
local -a active_model_formulae
_arguments \
'(-v --verbose)'{-v,--verbose}'[Enables verbose object printing]' \
'(-d --debug)'{-d,--debug}'[Enables printing proper Ruby stacktrace]' \
'(-w --webcommand)'{-w,--webcommand}'[Accepts web commands.]' \
'(-j --jsoncommand)'{-j,--jsoncommand}'[Same as -w but not exposed in web UI.]' \
'(-n --no-color)'{-n,--no-color}'[Disables console color. Useful for script wrapping.]' \
'(-V --version)'{-V,--version}'[Display the version of Razor]' \
'(-h --help)'{-h,--help}'[Display help info]' \
'*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "razor subcommand" _1st_arguments
return
fi
case "$words[1]" in
active_model)
_arguments \
'(-h --help)'{-h,--help}'[Dipslay help info]' \
'1: :->actions' && return 0
if [[ "$state" == actions ]]; then
_describe -t commands "razor active_model" _active_model_arguments
fi ;;
image)
_arguments \
'(-h --help)'{-h,--help}'[Dipslay help info]' \
'1: :->actions' \
'*::options:->options' && ret=0
case $state in
actions)
_describe -t commands "razor image" _image_arguments
;;
options)
if [[ "$words[1]" == 'add' ]]; then
_arguments \
'(-t --type)'{-t,--type}'[The type of image (mk, os, win, or esxi)]' \
'(-p --path)'{-p,--path}'[The local path to the image ISO]' \
'(-n --name)'{-n,--name}'[The logical name to use (os/win images only)]' \
'(-v --version)'{-v,--version}'[The version to use (os/win images only)]' \
'(-h --help)'{-h,--help}'[Display image add help info.]' && ret=0
else
_arguments '(-h --help)'{-h,--help}'[Dipslay help info]' && ret=0
fi
;;
esac
;;
model)
_arguments \
'(-h --help)'{-h,--help}'[Dipslay help info]' \
'1: :->actions' \
'*::options:->options' && ret=0
case $state in
actions)
_describe -t commands "razor model" _model_arguments
;;
options)
if [[ "$words[1]" == 'add' ]]; then
_arguments \
'(-t --template)'{-t,--template}"[The model template to use for the new model.]" \
'(-l --label)'{-l,--label}'[The label to use for the new model.]' \
'(-i --image-uuid)'{-i,--image-uuid}'[The image UUID to use for the new model.]' \
'(-h --help)'{-h,--help}'[Display model add help info.]' && ret=0
#elif [[ "$words[1]" == 'update' ]]; then
#_arguments \
#'(-l --label)'{-l,--label}'[The new label to use for the model.]' \
#'(-i --image-uuid)'{-i,--image-uuid}'[The new image UUID to use for the model.]' \
#'(-c --change-metadata)'{-c,--change-metadata}"[Used to trigger a change in the model's meta-data]" \
#'(-h --help)'{-h,--help}'[Display this screen.]' && ret=0
else
_arguments '(-h --help)'{-h,--help}'[Dipslay help info]' && ret=0
fi
;;
esac
;;
node)
_arguments \
'(-h --help)'{-h,--help}'[Dipslay help info]' \
'1: :->actions' && ret=0
if [[ "$state" == actions ]]; then
_describe -t commands "razor node" _node_arguments
fi ;;
policy)
_arguments \
'(-h --help)'{-h,--help}'[Dipslay help info]' \
'1: :->actions' \
'*::options:->options' && ret=0
case $state in
actions)
_describe -t commands "razor policy" _policy_arguments
;;
options)
if [[ "$words[1]" == 'add' ]]; then
_arguments \
'(-p --template)'{-p,--template}'[The policy template name to use.]' \
'(-l --label)'{-l,--label}'[A label to name this policy.]' \
'(-m --model-uuid)'{-m,--model-uuid}'[The model to attach to the policy.]' \
'(-v --vmodel-uuid)'{-v,--vmodel-uuid}'[The vmodel to attach to the policy.]' \
'(-b --broker-uuid)'{-b,--broker-uuid}"[The broker to attach to the policy \[default: none\].]" \
'(-e --enabled)'{-e,--enabled}"[Should policy be enabled (true|false) \[default: false\]?]" \
'(-x --maximum)'{-x,--maximum}"[Sets the policy maximum count for nodes \[default: 0\].]" \
'(-h, --help)'{-h,--help}'[Display policy add help info.]' && ret=0
#elif [[ "$words[1]" == 'update' ]]; then
#_arguments \
#'(-l --label)'{-l --label}'[A label to name this policy.]' \
#'(-m --model-uuid)'{-m,--model-uuid}'[The model to attached to the policy.]' \
#'(-v --vmodel-uuid)'{-v,--vmodel-uuid}'[The vmodel attached to the policy [defualt: none].]' \
#'(-b --broker-uuid)'{-b,--broker-uuid}'[The broker attached to the policy [default: none].]' \
#'(-e --enabled)'{-e,--enabled}'[Should policy be enabled (true|false) [default: false]?]' \
#'(-x --maximum)'{-x,--maximum}'[Sets the policy maximum count for nodes [default: 0].]' \
#'(-n --new-line-number)'{-n,--new-line-number}'[Change policy rule number.]' \
#'(-h --help)'{-h,--help}'[Display this screen.]' && ret=0
else
_arguments '(-h --help)'{-h,--help}'[Dipslay help info]' && ret=0
fi
;;
esac
;;
tag)
_arguments \
'(-h --help)'{-h,--help}'[Dipslay help info]' \
'1: :->actions' \
'*::options:->options' && ret=0
case $state in
actions)
_describe -t commands "razor tag" _tag_arguments
;;
options)
if [[ "$words[1]" == 'add' ]]; then
_arguments \
'(-n --name)'{-n,--name}'[Name for the tagrule being created]' \
'(-t --tag)'{-t,--tag}'[Tag for the tagrule being created]' \
'(-h --help)'{-h,--help}'[ Display tage add help info.]' && ret=0
#elif [[ "$words[1]" == 'update' ]]; then
#_arguments \
#'(-n --name)'{-n,--name}'[Name for the tagrule being created]' \
#'(-t --tag)'{-t,--tag}'[Tag for the tagrule being created]' \
#'(-h --help)'{-h,--help}'[Display this screen.]' && ret=0
#elif [[ "$words[1]" == 'matcher' ]]; then
#_arguments \
#'(-h --help)'{-h,--help}'[Dipslay help info]' \
#'1: :->matcher_actions' && ret=0
#'*::options:->matcher_options' && ret=0
#case $state in
#matcher_actions)
#declare -a matcher_commands
#matcher_commands=()
#_describe -t commands 'razor tag matcher' matcher_commands && ret=0
#;;
#matcher_options)
#case $words[1] in
#add)
#;;
#update)
#;;
#esac
#;;
#esac
#;;
else
_arguments '(-h --help)'{-h,--help}'[Dipslay help info]' && ret=0
fi
;;
esac
;;
vmodel)
_arguments \
'(-h --help)'{-h,--help}'[Dipslay help info]' \
'1: :->actions' \
'*::options:->options' && ret=0
case $state in
actions)
_describe -t commands "razor vmodel" _vmodel_arguments
;;
options)
if [[ "$words[1]" == 'add' ]]; then
_arguments \
'(-t --template)'{-t,--template}'[The vmodel template to use for the new vmodel.]' \
'(-l --label)'{-l,--label}'[The label to use for the new vmodel.]' \
'(-h --help)'{-h,--help}'[Display vmodel add help info.]' && ret=0
#elif [[ "$words[1]" == 'update' ]]; then
#_arguments \
#'(-l --label)'{-l,--label}'[The new label to use for the vmodel.]' \
#'(-c --change-metadata)'{-c,--change-metadata}"[Used to trigger a change in the vmodel's meta-data]" \
#'(-h --help)'{-h,--help}'[Display this screen.]' && ret=0
else
_arguments '(-h --help)'{-h,--help}'[Dipslay help info]' && ret=0
fi
;;
esac
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment