Module: CLAideCompletion::Generator

Defined in:
lib/claide_completion/generator.rb,
lib/claide_completion/generator/zsh.rb

Defined Under Namespace

Classes: ShellCompletionNotFound, Zsh

Class Method Summary collapse

Class Method Details

.generate(command, shell = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/claide_completion/generator.rb', line 9

def self.generate(command, shell = nil)
  shell ||= ENV['SHELL'].split(File::SEPARATOR).last
  begin
    generator = const_get(shell.capitalize.to_sym)
  rescue NameError
    raise ShellCompletionNotFound,  'Auto-completion generator for ' \
      "the `#{shell}` shell is not implemented."
  end
  generator.new(command).generate
end

.indent(string, indentation) ⇒ String

Indents the lines of the given string except the first one to the given level. Uses two spaces per each level.

Parameters:

  • string (String)

    The string to indent.

  • indentation (Fixnum)

    The indentation amount.

Returns:

  • (String)

    An indented string.



31
32
33
# File 'lib/claide_completion/generator.rb', line 31

def indent(string, indentation)
  string.gsub("\n", "\n#{' ' * indentation * 2}")
end