Class: Toys::Completion::Context
- Inherits:
 - 
      Object
      
        
- Object
 - Toys::Completion::Context
 
 
- Defined in:
 - lib/toys/completion.rb
 
Overview
The context in which to determine completion candidates.
Instance Attribute Summary collapse
- 
  
    
      #cli  ⇒ Toys::CLI 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The CLI being run.
 - 
  
    
      #fragment  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The current string fragment to complete.
 - 
  
    
      #fragment_prefix  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
A non-completed prefix for the current fragment.
 - 
  
    
      #previous_words  ⇒ Array<String> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
All previous words.
 
Instance Method Summary collapse
- 
  
    
      #[](key)  ⇒ Object 
    
    
      (also: #get)
    
  
  
  
  
  
  
  
  
  
    
Get data for arbitrary key.
 - 
  
    
      #arg_parser  ⇒ Toys::ArgParser 
    
    
  
  
  
  
  
  
  
  
  
    
Current ArgParser indicating the status of argument parsing up to this point.
 - 
  
    
      #args  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    
An array of complete arguments passed to the tool, prior to the fragment to complete.
 - 
  
    
      #initialize(cli:, previous_words: [], fragment_prefix: "", fragment: "", **params)  ⇒ Context 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Create a completion context.
 - 
  
    
      #tool  ⇒ Toys::ToolDefinition 
    
    
  
  
  
  
  
  
  
  
  
    
The tool being invoked, which should control the completion.
 - 
  
    
      #with(**delta_params)  ⇒ Toys::Completion::Context 
    
    
  
  
  
  
  
  
  
  
  
    
Create a new completion context with the given modifications.
 
Constructor Details
#initialize(cli:, previous_words: [], fragment_prefix: "", fragment: "", **params) ⇒ Context
Create a completion context
      30 31 32 33 34 35 36 37 38 39 40 41 42 43  | 
    
      # File 'lib/toys/completion.rb', line 30 def initialize(cli:, previous_words: [], fragment_prefix: "", fragment: "", **params) @cli = cli @previous_words = previous_words @fragment_prefix = fragment_prefix @fragment = fragment extra_params = { cli: cli, previous_words: previous_words, fragment_prefix: fragment_prefix, fragment: fragment } @params = params.merge(extra_params) @tool = nil @args = nil @arg_parser = nil end  | 
  
Instance Attribute Details
#cli ⇒ Toys::CLI (readonly)
The CLI being run.
      59 60 61  | 
    
      # File 'lib/toys/completion.rb', line 59 def cli @cli end  | 
  
#fragment ⇒ String (readonly)
The current string fragment to complete
      77 78 79  | 
    
      # File 'lib/toys/completion.rb', line 77 def fragment @fragment end  | 
  
#fragment_prefix ⇒ String (readonly)
A non-completed prefix for the current fragment.
      71 72 73  | 
    
      # File 'lib/toys/completion.rb', line 71 def fragment_prefix @fragment_prefix end  | 
  
#previous_words ⇒ Array<String> (readonly)
All previous words.
      65 66 67  | 
    
      # File 'lib/toys/completion.rb', line 65 def previous_words @previous_words end  | 
  
Instance Method Details
#[](key) ⇒ Object Also known as: get
Get data for arbitrary key.
      84 85 86  | 
    
      # File 'lib/toys/completion.rb', line 84 def [](key) @params[key] end  | 
  
#arg_parser ⇒ Toys::ArgParser
Current ArgParser indicating the status of argument parsing up to this point.
      114 115 116 117  | 
    
      # File 'lib/toys/completion.rb', line 114 def arg_parser lookup_tool @arg_parser ||= ArgParser.new(@cli, @tool).parse(@args) end  | 
  
#args ⇒ Array<String>
An array of complete arguments passed to the tool, prior to the fragment to complete.
      103 104 105 106  | 
    
      # File 'lib/toys/completion.rb', line 103 def args lookup_tool @args end  | 
  
#tool ⇒ Toys::ToolDefinition
The tool being invoked, which should control the completion.
      93 94 95 96  | 
    
      # File 'lib/toys/completion.rb', line 93 def tool lookup_tool @tool end  | 
  
#with(**delta_params) ⇒ Toys::Completion::Context
Create a new completion context with the given modifications.
      51 52 53  | 
    
      # File 'lib/toys/completion.rb', line 51 def with(**delta_params) Context.new(**@params.merge(delta_params)) end  |