Sha256: 2e6445cb4b24f8446ee6d641c41ba677bea88a1ad51cbc97173fe6a41f7407a7

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

require 'claide/command/shell_completion_helper/zsh_completion_generator'

module CLAide
  class Command
    module ShellCompletionHelper
      # Returns the completion template generated for the given command for the
      # given shell. If the shell is not provided it will be inferred by the
      # environment.
      #
      def self.completion_template(command, shell = nil)
        shell ||= ENV['SHELL'].split('/').last
        case shell
        when 'zsh'
          ZSHCompletionGenerator.generate(command)
        else
          raise Help, "Auto-completion generator for `#{shell}` shell not" \
            ' implemented.'
        end
      end

      # Indents the lines of the given string except the first one to the given
      # level. Uses two spaces per each level.
      #
      # @param  [String] string
      #         The string to indent.
      #
      # @param  [Fixnum] indentation
      #         The indentation amount.
      #
      # @return [String] An indented string.
      #
      def self.indent(string, indentation)
        string.gsub("\n", "\n#{' ' * indentation * 2}")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
claide-0.7.0 lib/claide/command/shell_completion_helper.rb
claide-0.6.1 lib/claide/command/shell_completion_helper.rb
claide-0.6.0 lib/claide/command/shell_completion_helper.rb