Module: Tabry::Fish::Wrapper

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

Constant Summary collapse

DESCRIPTION_MAX_LENGTH =
50

Class Method Summary collapse

Class Method Details

.format_description(description) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/tabry/shells/fish/wrapper.rb', line 38

def self.format_description(description)
  if description.nil?
    ""
  elsif description.length > DESCRIPTION_MAX_LENGTH
    "#{description[0..(DESCRIPTION_MAX_LENGTH - 3)]}..."
  else
    description
  end
end

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



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

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, { descriptions: true })

  if Tabry::Util.debug?
    $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 { |opt, desc| "#{Shellwords.escape(opt)}\t#{format_description(desc)}" }.join("\n")
  if special_opts.any?
    puts
    puts special_opts.join("\n")
  end
end