Module: Tabry::Bash::Wrapper

Defined in:
lib/tabry/shells/bash/wrapper.rb

Class Method Summary collapse

Class Method Details

.run(cmd_line, comp_point, config: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tabry/shells/bash/wrapper.rb', line 13

def self.run(cmd_line, comp_point, config: nil)
  cmd_name, args, last_arg = Tabry::ShellTokenizer.split_with_comppoint(cmd_line, comp_point)
  opts = Tabry::Runner.new(config: config || cmd_name).options(args, last_arg)

  if Tabry::Util.debug?
    require "json"
    $stderr.puts
    warn "debug: got command line and comp_point: #{cmd_line.inspect}, #{comp_point}"
    warn "using args: #{args.inspect}"
    warn "using lastarg: #{last_arg.inspect}"
    warn "results from Tabry#options(): #{opts.inspect}"
    warn "--- end debug output ---"
  end

  normal_opts = opts.select { |t| t.is_a?(String) }
  special_opts = opts.select { |t| t.is_a?(Symbol) }

  puts normal_opts.map { |t| Shellwords.escape(t) }.join("\n")
  if special_opts.any?
    puts
    puts special_opts.join("\n")
  end
end