Module: SeccompTools::CLI

Defined in:
lib/seccomp-tools/cli/cli.rb,
lib/seccomp-tools/cli/asm.rb,
lib/seccomp-tools/cli/emu.rb,
lib/seccomp-tools/cli/base.rb,
lib/seccomp-tools/cli/dump.rb,
lib/seccomp-tools/cli/audit.rb,
lib/seccomp-tools/cli/disasm.rb,
lib/seccomp-tools/cli/explain.rb,
lib/seccomp-tools/cli/dumpable.rb,
lib/seccomp-tools/cli/completion.rb,
lib/seccomp-tools/cli/filter_input.rb

Overview

Handle CLI arguments parse.

Defined Under Namespace

Modules: Dumpable, FilterInput Classes: Asm, Audit, Base, Completion, Disasm, Dump, Emu, Explain

Constant Summary collapse

COMMANDS =

Handled commands

{
  'asm' => SeccompTools::CLI::Asm,
  'audit' => SeccompTools::CLI::Audit,
  'completion' => SeccompTools::CLI::Completion,
  'disasm' => SeccompTools::CLI::Disasm,
  'dump' => SeccompTools::CLI::Dump,
  'emu' => SeccompTools::CLI::Emu,
  'explain' => SeccompTools::CLI::Explain
}.freeze
USAGE =

Main usage message.

<<EOS.sub('%COMMANDS', COMMANDS.map { |k, v| "\t#{k}\t#{v::SUMMARY}" }.join("\n")).freeze
Usage: seccomp-tools [--version] [--help] <command> [<options>]

List of commands:

%COMMANDS

See 'seccomp-tools <command> --help' to read about a specific subcommand.
EOS

Class Method Summary collapse

Class Method Details

.show(msg) ⇒ void

This method returns an undefined value.

Writes a message to stdout, followed by a newline.

Parameters:

  • msg (String)

    The message to be written.



70
71
72
# File 'lib/seccomp-tools/cli/cli.rb', line 70

def show(msg)
  puts msg
end

.work(argv) ⇒ void

This method returns an undefined value.

Main working method of CLI.

Examples:

work(%w[--help])
#=> # usage message
work(%w[--version])
#=> # version message

Parameters:

  • argv (Array<String>)

    Command line arguments.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/seccomp-tools/cli/cli.rb', line 48

def work(argv)
  # all -h equivalent to --help
  argv = argv.map { |a| a == '-h' ? '--help' : a }
  idx = argv.index { |c| !c.start_with?('-') }
  preoption = idx.nil? ? argv.shift(argv.size) : argv.shift(idx)

  # handle --version or --help or nothing
  return show("SeccompTools Version #{SeccompTools::VERSION}") if preoption.include?('--version')
  return show(USAGE) if idx.nil?

  # let's handle commands
  cmd = argv.shift
  argv = %w[--help] if preoption.include?('--help')
  return show(invalid(cmd)) if COMMANDS[cmd].nil?

  COMMANDS[cmd].new(argv).handle
end