Class: OsCtl::Lib::Cli::Completion::Bash::OptArg

Inherits:
Object
  • Object
show all
Defined in:
lib/libosctl/cli/completion/bash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ OptArg

Returns a new instance of OptArg.

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :cmd (:all, Array<Symbol>)
  • :name (Symbol)
  • :expand (String)


12
13
14
15
16
17
18
19
20
21
# File 'lib/libosctl/cli/completion/bash.rb', line 12

def initialize(opts)
  @cmd = if opts[:cmd].is_a?(Symbol)
           opts[:cmd]
         else
           opts[:cmd].map(&:to_s)
         end

  @name = opts[:name].to_s
  @expand = opts[:expand]
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



6
7
8
# File 'lib/libosctl/cli/completion/bash.rb', line 6

def cmd
  @cmd
end

#expandObject (readonly)

Returns the value of attribute expand.



6
7
8
# File 'lib/libosctl/cli/completion/bash.rb', line 6

def expand
  @expand
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/libosctl/cli/completion/bash.rb', line 6

def name
  @name
end

Instance Method Details

#applicable?(cmd_path, arg) ⇒ Boolean

Parameters:

  • cmd_path (Array<String>)
  • arg (String)

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
# File 'lib/libosctl/cli/completion/bash.rb', line 25

def applicable?(cmd_path, arg)
  return false if name != arg
  return true if cmd == :all

  cmd.zip(cmd_path).each do |x, y|
    return false if y.nil? || x != y
  end

  true
end