Class: Thor::Completion::Bash::Subcmd
- Defined in:
- lib/thor/completion/bash/subcmd.rb
Overview
Thor added as a Thor.subcommand to the includer of Thor::Completion::Bash to expose Bash completion endpoints.
Constant Summary
Constants inherited from Thor
AmbiguousTaskError, DynamicTask, HELP_MAPPINGS, HiddenTask, ROOT, TEMPLATE_EXTNAME, THOR_RESERVED_WORDS, THOR_VERSION, Task, UndefinedTaskError, VERSION
Instance Attribute Summary
Attributes included from Base
#args, #options, #parent_options
Instance Method Summary collapse
-
#complete(*_) ⇒ void
Execute Bash completion.
-
#setup ⇒ nil
Print Bash source code to hook into ‘complete` to `$stdout`.
Methods inherited from Thor
banner, baseclass, check_unknown_options!, check_unknown_options?, command_help, create_command, default_command, desc, disable_required_check, disable_required_check!, disable_required_check?, dispatch, dynamic_command_class, example, find_command_possibilities, help, #help, initialize_added, long_desc, map, method_option, method_options, normalize_command_name, #option_kwds, package_name, printable_commands, register, retrieve_command_name, running_from_source?, stop_on_unknown_option, stop_on_unknown_option!, stop_on_unknown_option?, subcommand, subcommand_classes, subcommand_help, subcommands
Methods included from Base
included, #initialize, #on_run_error, #on_run_success, register_klass_file, subclass_files, subclasses
Instance Method Details
#complete(*_) ⇒ void
This method returns an undefined value.
Execute Bash completion.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/thor/completion/bash/subcmd.rb', line 52 def complete *_ # logger.level = :trace logger.trace "Starting Bash complete...", ARGV: ARGV, args: args args = ARGV.dup args.shift while args[0] != '--' args.shift cur, prev, cword, split, *words = args request = Request.new \ cur: cur, # options[:cur], prev: prev, # options[:prev], cword: cword.to_i, # options[:cword], split: split.truthy?, # options[:split], words: words logger.trace "Bash complete Request loaded", request: request results = begin self.class.target.bash_complete( request: request, index: 1 ) rescue StandardError => error logger.error "Error raised processing Bash complete request", { request: request }, error [] end joined = results.shelljoin logger.trace "Sending Bash compelte response", request: request, results: results, joined: joined puts joined exit true end |
#setup ⇒ nil
Print Bash source code to hook into ‘complete` to `$stdout`.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/thor/completion/bash/subcmd.rb', line 111 def setup bin = File.basename $0 name = bin.underscore erb_src_path = ::Thor::ROOT.join 'support', 'completion', 'complete.inc.bash.erb' erb_src = erb_src_path.read bash_src = binding.erb erb_src puts bash_src nil end |