Class: Deploio::CompletionGenerator
- Inherits:
-
Object
- Object
- Deploio::CompletionGenerator
- Defined in:
- lib/deploio/completion_generator.rb
Overview
Generates zsh completion script from Thor command metadata. Can be reused with any Thor-based CLI by passing the CLI class.
Constant Summary collapse
- TEMPLATE_PATH =
File.("templates/completion.zsh.erb", __dir__)
- PASSTHROUGH_COMMANDS =
Commands that pass through to external programs (like exec) These get '*:command:_normal' as their final argument
%w[exec run].freeze
Instance Attribute Summary collapse
-
#cli_class ⇒ Object
readonly
Returns the value of attribute cli_class.
-
#option_completers ⇒ Object
readonly
Returns the value of attribute option_completers.
-
#positional_completers ⇒ Object
readonly
Returns the value of attribute positional_completers.
-
#program_name ⇒ Object
readonly
Returns the value of attribute program_name.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(cli_class = nil, option_completers: {}, positional_completers: {}, program_name: nil) ⇒ CompletionGenerator
constructor
A new instance of CompletionGenerator.
Constructor Details
#initialize(cli_class = nil, option_completers: {}, positional_completers: {}, program_name: nil) ⇒ CompletionGenerator
Returns a new instance of CompletionGenerator.
32 33 34 35 36 37 |
# File 'lib/deploio/completion_generator.rb', line 32 def initialize(cli_class = nil, option_completers: {}, positional_completers: {}, program_name: nil) @cli_class = cli_class || default_cli_class @program_name = program_name || derive_program_name @option_completers = default_option_completers.merge(option_completers) @positional_completers = default_positional_completers.merge(positional_completers) end |
Instance Attribute Details
#cli_class ⇒ Object (readonly)
Returns the value of attribute cli_class.
24 25 26 |
# File 'lib/deploio/completion_generator.rb', line 24 def cli_class @cli_class end |
#option_completers ⇒ Object (readonly)
Returns the value of attribute option_completers.
24 25 26 |
# File 'lib/deploio/completion_generator.rb', line 24 def option_completers @option_completers end |
#positional_completers ⇒ Object (readonly)
Returns the value of attribute positional_completers.
24 25 26 |
# File 'lib/deploio/completion_generator.rb', line 24 def positional_completers @positional_completers end |
#program_name ⇒ Object (readonly)
Returns the value of attribute program_name.
24 25 26 |
# File 'lib/deploio/completion_generator.rb', line 24 def program_name @program_name end |
Instance Method Details
#generate ⇒ Object
39 40 41 42 |
# File 'lib/deploio/completion_generator.rb', line 39 def generate template = File.read(TEMPLATE_PATH) ERB.new(template, trim_mode: "-").result(binding) end |