Class: SeccompTools::CLI::Completion

Inherits:
Base
  • Object
show all
Defined in:
lib/seccomp-tools/cli/completion.rb

Overview

Handle 'completion' command.

Constant Summary collapse

SUMMARY =

Summary of this command.

'Print a shell completion script.'
USAGE =

Usage of this command.

"completion - #{SUMMARY}\n\nUsage: seccomp-tools completion <bash|zsh|fish>".freeze
SCRIPTS =

Maps a shell name to the completion script that ships with the gem.

{ 'bash' => 'seccomp-tools.bash', 'zsh' => '_seccomp-tools', 'fish' => 'seccomp-tools.fish' }.freeze

Instance Attribute Summary

Attributes inherited from Base

#argv, #option

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SeccompTools::CLI::Base

Instance Method Details

#handlevoid

This method returns an undefined value.

Writes the completion script for the requested shell to stdout.



29
30
31
32
33
34
35
36
37
# File 'lib/seccomp-tools/cli/completion.rb', line 29

def handle
  return unless super

  shell = argv.shift
  file = SCRIPTS[shell]
  return CLI.show(parser.help) if file.nil?

  output { File.read(File.join(__dir__, '..', '..', '..', 'completions', file)) }
end

#parserOptionParser

Define option parser.

Returns:

  • (OptionParser)

    The parser of this command's options.



21
22
23
24
25
# File 'lib/seccomp-tools/cli/completion.rb', line 21

def parser
  @parser ||= OptionParser.new do |opt|
    opt.banner = usage
  end
end