class Samovar::Completion::Context
The context provided to dynamic completion callbacks.
Attributes
@attribute [Array(String)] The completed words before the current token.
@attribute [String] The token being completed.
@attribute [Hash] The environment for completion callbacks.
@attribute [Object | Nil] The parser row whose value is being completed.
@attribute [Table] The command table to complete.
Public Class Methods
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/context.rb, line 18 def self.for(command_class, arguments, environment: ENV) arguments = arguments.dup current = arguments.pop || "" return self.new( command_class.table.merged, arguments, current, environment: environment, ) end
Build a context for a command class and argument list.
@parameter command_class [Class] The command class to complete. @parameter arguments [Array(String)] The truncated command-line arguments. @parameter environment [Hash] The environment for completion callbacks. @returns [Context] The completion context.
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/context.rb, line 37 def initialize(table, arguments, current, row = nil, environment: ENV) @table = table @arguments = arguments @current = current @row = row @environment = environment end
Initialize a new completion context.
@parameter table [Table] The command table to complete. @parameter arguments [Array(String)] The completed words before the current token. @parameter current [String] The token being completed. @parameter row [Object | Nil] The parser row whose value is being completed. @parameter environment [Hash] The environment for completion callbacks.
Public Instance Methods
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/context.rb, line 77 def complete complete_rows(@table, @arguments.dup) end
Complete the current command class.
@returns [Result] The completion result.
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/context.rb, line 86 def complete_command(command_class, words = []) complete_rows(command_class.table.merged, words) end
Complete the given command class with completed words.
@parameter command_class [Class] The command class to complete. @parameter words [Array(String)] The completed words before the current token. @returns [Result] The completion result.
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/context.rb, line 96 def complete_rows(table, input) collected = [] table.each do |row| if row.respond_to?(:complete) if result = row.complete(input, self, collected) return result end end end return Result.new(collected) end
Complete the rows in a command table. The input array is mutable and may be consumed by parser rows.
@parameter table [Table] The command table to complete. @parameter input [Array(String)] The mutable completed words to consume. @returns [Result] The completion result.
Source
# File vendor/bundle/ruby/4.0.0/gems/samovar-2.5.1/lib/samovar/completion/context.rb, line 64 def with_row(row) return self.class.new( @table, @arguments, @current, row, environment: @environment, ) end
Create a context for completing the given parser row.
@parameter row [Object] The parser row whose value is being completed. @returns [Context] The specialized completion context.