Sha256: 2e2badad5eb986076586a9de89da482dcc8d9a7309d7458ccf676231ecd6abc0

Contents?: true

Size: 835 Bytes

Versions: 4

Compression:

Stored size: 835 Bytes

Contents

class Ppl::Command::Completion < Ppl::Application::Command

  name        "completion"
  description "Output shell completion function"

  attr_writer :completions_directory

  def options(parser, options)
    parser.banner = "usage: ppl completion <shell>"
  end

  def execute(input, output)
    shell_name = require_shell_name(input)
    location = require_completion_existence(shell_name)
    output.line(File.read(location))
  end

  private

  def require_shell_name(input)
    if input.arguments.first.nil?
      raise Ppl::Error::IncorrectUsage, "No shell specified"
    end
    input.arguments.shift
  end

  def require_completion_existence(shell_name)
    path = File.join(@completions_directory.path, shell_name)
    if !File.exists? path
      raise Ppl::Error::CompletionNotFound, shell_name
    end
    path
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ppl-4.0.3 lib/ppl/command/completion.rb
ppl-4.0.2 lib/ppl/command/completion.rb
ppl-4.0.1 lib/ppl/command/completion.rb
ppl-4.0.0 lib/ppl/command/completion.rb