Class: Laborantin::Commands::Complete

Inherits:
Laborantin::Command show all
Defined in:
lib/laborantin/runner/commands/complete.rb

Instance Attribute Summary

Attributes inherited from Laborantin::Command

#args, #opts, #runner

Attributes included from Metaprog::Completeable

#completion_block

Instance Method Summary collapse

Methods inherited from Laborantin::Command

describe, each, execute, inherited, #initialize, option, plumbery!, plumbery?, porcelain?, #puts, #run

Methods included from Metaprog::Completeable

#complete, #completion_propositions_iterating_on

Constructor Details

This class inherits a constructor from Laborantin::Command

Instance Method Details

#complete_option(opt, cmd) ⇒ Object



46
47
48
# File 'lib/laborantin/runner/commands/complete.rb', line 46

def complete_option(opt, cmd)
  opt.completion_block.call(cmd) if opt.completion_block
end

#list_argv_and_options_line(klass, cmd) ⇒ Object



77
78
79
# File 'lib/laborantin/runner/commands/complete.rb', line 77

def list_argv_and_options_line(klass, cmd)
  klass.completion_block.call(cmd) if klass.completion_block
end

#list_long_option(klass, cmd) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/laborantin/runner/commands/complete.rb', line 50

def list_long_option(klass, cmd)
  # in the options of the command look for the one with long
  opt = klass.options.find{|o| o.cli_long == cmd.split.last}

  if opt 
    complete_option(opt,cmd)
  else
  end
end

#list_mapping_klasses(str) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/laborantin/runner/commands/complete.rb', line 14

def list_mapping_klasses(str)
  #separate the case for modules
  # labor config <tab>
  # should propose config set|foo
  if str == 'labor'
    Command.reject(&:plumbery?).map{|cmd| runner.argv_klass_name(cmd).first}
  else
    size = str.split.size
    cmds = Command.reject{|cmd| cmd.plumbery?}.map do |cmd|
      runner.argv_klass_name(cmd).slice(0, size)
    end

    match = cmds.find do |cmd|
      cmd.join(' ') == str
    end

    if match
      cmds = Command.reject{|cmd| cmd.plumbery?}.map do |cmd|
        runner.argv_klass_name(cmd).slice(0, size+1)
      end
    end

    cmds.select do |cmd|
      tst = cmd.join(' ').start_with?(str) 
      STDERR.puts "#{cmd} | #{str} | #{tst}" if $DEBUG
      tst 
    end.map do |cmd|
      cmd.last
    end
  end
end

#list_short_option(klass, cmd) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/laborantin/runner/commands/complete.rb', line 60

def list_short_option(klass, cmd)
  # in the options of the command look for the one with long
  opt = klass.options.find{|o| o.cli_short == cmd.split.last}
  if opt 
    complete_option(opt,cmd)
  else
    if cmd.split[-2].start_with?('-')
      opt = klass.options.find{|o| o.cli_short == cmd.split[-2]}
      complete_option(opt,cmd) if opt
    else
      klass.options.map(&:cli_short).select{|w|
        w.start_with?(cmd)
      }
    end
  end
end

#maps_to_a_klass?(cmd) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/laborantin/runner/commands/complete.rb', line 10

def maps_to_a_klass?(cmd)
  runner.command_for_argv(cmd.split(' '))
end