Class: Ronin::Core::CLI::CompletionCommand
- Includes:
- CommandKit::Completion::Install
- Defined in:
- lib/ronin/core/cli/completion_command.rb
Overview
Common base class for all ronin-* completion
commands.
Example
# lib/ronin/foo/cli/commands/completion.rb
require 'ronin/foo/root'
require 'ronin/core/cli/completion_command'
module Ronin
module Foo
class CLI
class Command < Core::CLI::CompletionCommand
man_dir File.join(ROOT,'man')
man_page 'ronin-foo-completion.1'
completion_file File.join(ROOT,'data','completions','ronin-foo')
end
end
end
end
Instance Attribute Summary collapse
-
#mode ⇒ :print, ...
readonly
The command mode.
Class Method Summary collapse
-
.completion_file(new_completion_file = nil) ⇒ String
Gets or sets the completion file for the
completion
command.
Instance Method Summary collapse
-
#completion_file ⇒ String
The
completion
commands registered completion file. -
#initialize(**kwargs) ⇒ CompletionCommand
constructor
Initializes the
completion
command. -
#install_completion_file(completion_file = self.completion_file) ⇒ Object
private
Installs the
completion
command's CompletionCommand.completion_file for the currentSHELL
. -
#print_completion_file(completion_file = self.completion_file) ⇒ Object
private
Prints the
completion
command's CompletionCommand.completion_file to stdout. -
#run ⇒ Object
Runs the
completion
command. -
#uninstall_completion_file(completion_file = self.completion_file) ⇒ Object
private
Uninstalls the
completion
command's CompletionCommand.completion_file.
Constructor Details
#initialize(**kwargs) ⇒ CompletionCommand
Initializes the completion
command.
114 115 116 117 118 |
# File 'lib/ronin/core/cli/completion_command.rb', line 114 def initialize(**kwargs) super(**kwargs) @mode = :print end |
Instance Attribute Details
#mode ⇒ :print, ... (readonly)
The command mode.
106 107 108 |
# File 'lib/ronin/core/cli/completion_command.rb', line 106 def mode @mode end |
Class Method Details
.completion_file(new_completion_file = nil) ⇒ String
Gets or sets the completion file for the completion
command.
73 74 75 76 77 78 79 |
# File 'lib/ronin/core/cli/completion_command.rb', line 73 def self.completion_file(new_completion_file=nil) if new_completion_file @completion_file = new_completion_file else @completion_file || raise(NotImplementedError,"#{self} did not set completion_file") end end |
Instance Method Details
#completion_file ⇒ String
The completion
commands registered completion file.
129 130 131 |
# File 'lib/ronin/core/cli/completion_command.rb', line 129 def completion_file self.class.completion_file end |
#install_completion_file(completion_file = self.completion_file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Installs the completion
command's completion_file for the current
SHELL
.
185 186 187 |
# File 'lib/ronin/core/cli/completion_command.rb', line 185 def install_completion_file(completion_file=self.completion_file) super(completion_file) end |
#print_completion_file(completion_file = self.completion_file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints the completion
command's completion_file to stdout.
172 173 174 |
# File 'lib/ronin/core/cli/completion_command.rb', line 172 def print_completion_file(completion_file=self.completion_file) super(completion_file) end |
#run ⇒ Object
Runs the completion
command.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ronin/core/cli/completion_command.rb', line 136 def run if shell_type == :fish print_error "shell completions for the fish shell are not currently supported" exit(-1) end case @mode when :print print_completion_file when :install install_completion_file if shell_type == :zsh puts "Ensure that you have the following lines added to your ~/.zshrc:" puts puts " autoload -Uz +X compinit && compinit" puts " autoload -Uz +X bashcompinit && bashcompinit" puts end when :uninstall uninstall_completion_file puts "Completion rules successfully uninstalled. Please restart your shell." else raise(NotImplementedError,"mode not implemented: #{@mode.inspect}") end end |
#uninstall_completion_file(completion_file = self.completion_file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Uninstalls the completion
command's completion_file.
197 198 199 |
# File 'lib/ronin/core/cli/completion_command.rb', line 197 def uninstall_completion_file(completion_file=self.completion_file) uninstall_completion_file_for(File.basename(completion_file)) end |