Sha256: e93e6d21e18be7b93fe6986deb2d0c90d204af2ea320873c5f8a62f4682eca0f

Contents?: true

Size: 1.86 KB

Versions: 20

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

require 'tty-progressbar'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'completion'))
require 'string'
require 'fish_completion'
require 'zsh_completion'
require 'bash_completion'

module Doing
  # Completion script generator
  module Completion
    class << self
      # Generate a completion script and output to file or
      # stdout
      #
      # @param      type  [String] shell to generate for (zsh|bash|fish)
      # @param      file  [String] Path to save to, or 'stdout'
      #
      def generate_completion(type: 'zsh', file: 'stdout')
        if type =~ /^all$/i
          Doing.logger.log_now(:warn, 'Generating:', 'all completion types, will use default paths')
          generate_completion(type: 'fish', file: 'lib/completion/doing.fish')
          Doing.logger.warn('File written:', "fish completions written to lib/completion/doing.fish")
          generate_completion(type: 'zsh', file: 'lib/completion/_doing.zsh')
          Doing.logger.warn('File written:', "zsh completions written to lib/completion/_doing.zsh")
          generate_completion(type: 'bash', file: 'lib/completion/doing.bash')
          Doing.logger.warn('File written:', "bash completions written to lib/completion/doing.bash")
          return
        end

        generator = case type.to_s
                    when /^f/i
                      FishCompletions.new
                    when /^b/i
                      BashCompletions.new
                    else
                      ZshCompletions.new
                    end

        result = generator.generate_completions

        if file =~ /^stdout$/i
          $stdout.puts result
        else
          File.open(File.expand_path(file), 'w') do |f|
            f.puts result
          end
          Doing.logger.warn('File written:', "#{type} completions written to #{file}")
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
doing-2.1.30 lib/doing/completion.rb
doing-2.1.29 lib/doing/completion.rb
doing-2.1.28 lib/doing/completion.rb
doing-2.1.27 lib/doing/completion.rb
doing-2.1.26 lib/doing/completion.rb
doing-2.1.25 lib/doing/completion.rb
doing-2.1.24 lib/doing/completion.rb
doing-2.1.23 lib/doing/completion.rb
doing-2.1.22 lib/doing/completion.rb
doing-2.1.21 lib/doing/completion.rb
doing-2.1.19 lib/doing/completion.rb
doing-2.1.18 lib/doing/completion.rb
doing-2.1.17 lib/doing/completion.rb
doing-2.1.16 lib/doing/completion.rb
doing-2.1.15 lib/doing/completion.rb
doing-2.1.14 lib/doing/completion.rb
doing-2.1.13 lib/doing/completion.rb
doing-2.1.12 lib/doing/completion.rb
doing-2.1.11 lib/doing/completion.rb
doing-2.1.10 lib/doing/completion.rb