#compdef <%= script_name %> # zsh shell completion script for <%= script_name %> # To regenerate this file: '<%= script_name %> adm --zsh-completion' # Generated on the <%= Time.now %> by <%= script_name %> v<%= PowerStencil::VERSION %> <% commands = PowerStencil.command_line_manager.commands -%> _<%= script_name %>() { local cmd local <%= script_name %>_sub_commands <%= script_name %>_sub_commands=(<%= commands.reject { |c| c.name.empty? }.sort { |a,b| a.name <=> b.name }.map(&:name).join ' ' %>) if (( CURRENT > 2)); then cmd=${words[2]} # Set the context for the subcommand. curcontext="${curcontext%:*:*}:power_stencil-$cmd" # Narrow the range of words we are looking at to exclude `<%= script_name %>' (( CURRENT-- )) shift words # Run the completion for the subcommand if (($<%= script_name %>_sub_commands[(Ie)$cmd])); then (( $+functions[_<%= script_name %>_cmd_$cmd] )) && _<%= script_name %>_cmd_$cmd else _values : \ <%= continued_multilines(root_command(commands).options.sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}, number_spaces: 10) %> fi else _values : \ <% root_command = nil -%> <% commands.sort { |a,b| a.name <=> b.name }.each do |command| -%> <% if command.root_command? -%> <% root_command = command -%> <% next -%> <% end -%> <%= command_representation command %> \ <% end -%> <%= continued_multilines(root_command.options.sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}, number_spaces: 8) %> fi } ############################################################################### # Sub-commands <% commands.reject { |c| c.name.empty? }.sort { |a,b| a.name <=> b.name }.each do |command| -%> # <%= command.name %> sub-command _<%= script_name %>_cmd_<%= command.name %>() { _arguments -s : \ <% command_param = default_command_param_type command options_lines = command.options.sort { |a,b| a.name <=> b.name }.map {|o| option_representation o} options_lines << command_param unless command_param.empty? -%> <%= continued_multilines(options_lines) %> } <% end %> ############################################################################### # Type handlers _get_completion_info() { local cmd="$@" res=$( eval ${cmd} 2>/dev/null ) echo ${res} } _power_stencil_project_root() { cur_dir=`pwd` psdir=".ps_project" while [[ "${cur_dir}" != "" && ! -e "${cur_dir}/${psdir}" ]]; do cur_dir=${cur_dir%/*} done echo "${cur_dir}" } _within_power_stencil_project() { local res=$( _power_stencil_project_root ) if [ -z "${res#"${res%%[! ]*}"}" ]; then return 1 fi return 0 } # Type entity _power_stencil_entity() { $( _within_power_stencil_project ) || return 'YOU_ARE_NOT_WITHIN_A_POWER_STENCIL_PROJECT' _values : $( _get_completion_info power_stencil adm --query-for-completion entities ) } # Type entity_type _power_stencil_entity_type() { $( _within_power_stencil_project ) || return 'YOU_ARE_NOT_WITHIN_A_POWER_STENCIL_PROJECT' _values : $( _get_completion_info power_stencil adm --query-for-completion entity-types ) } # Type scenario _power_stencil_scenario() { $( _within_power_stencil_project ) || return 'YOU_ARE_NOT_WITHIN_A_POWER_STENCIL_PROJECT' _values : $( _get_completion_info power_stencil adm --query-for-completion scenario ) } # Type log_level _power_stencil_log_level() { _values : $( echo 0 1 2 3 4 5 ) } # Type path _power_stencil_path() { _path_files } # Type completion_query_type _power_stencil_completion_query_type() { _values : $( echo entities entity-types scenario ) } # Type array and string _power_stencil_do_nothing() { return 1 } # Let's rock _<%= script_name %> "$@"