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/disasm.rb
Overview
Handle CLI arguments parse.
Defined Under Namespace
Classes: Asm, Base, Disasm, Dump, Emu
Constant Summary collapse
- COMMANDS =
Handled commands
{ 'asm' => SeccompTools::CLI::Asm, 'disasm' => SeccompTools::CLI::Disasm, 'dump' => SeccompTools::CLI::Dump, 'emu' => SeccompTools::CLI::Emu }.freeze
- USAGE =
Main usage message.
"Usage: seccomp-tools [--version] [--help] <command> [<options>]\n\nList of commands:\n\n%COMMANDS\n\nSee 'seccomp-tools <command> --help' to read about a specific subcommand.\n".sub('%COMMANDS', COMMANDS.map { |k, v| "\t#{k}\t#{v::SUMMARY}" }.join("\n")).freeze
Class Method Summary collapse
-
.show(msg) ⇒ false
Just write message to stdout.
-
.work(argv) ⇒ void
Main working method of CLI.
Class Method Details
.show(msg) ⇒ false
Just write message to stdout.
65 66 67 68 |
# File 'lib/seccomp-tools/cli/cli.rb', line 65 def show(msg) puts msg false end |
.work(argv) ⇒ void
This method returns an undefined value.
Main working method of CLI.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/seccomp-tools/cli/cli.rb', line 42 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 |