class Pedant::Cli
Public Class Methods
run()
click to toggle source
# File lib/pedant/cli.rb, line 33 def self.run options = { input_mode: :filesystem, output_mode: :terminal, verbosity: 0 } Command.initialize! @@optparse = OptionParser.new do |opts| opts.banner = "Usage: pedant [global-options] [command [command-options] [args]]" opts.separator "" opts.separator "Global settings:" opts.separator "" opts.separator "Common operations:" opts.on('-h', '--help', 'Display this help screen.') do puts opts exit 1 end opts.on('-l', '--list', 'Display the list of available commands.') do puts Command.list exit 1 end opts.on('-v') do puts "The -v argument now comes after the `check` subcommand. Like so:" puts " pedant check -v file.nasl" puts "For the version, do -V or --version." exit 1 end opts.on('-V', '--version', 'Display the version of Pedant.') do puts "#{Pedant::VERSION}" exit end end @@optparse.order! # Sanity check the command. usage("No command was specified.") if ARGV.empty? cmd = ARGV.shift cls = Command.find(cmd) usage("Command '#{cmd}' not supported.") if cls.nil? # Run the command. cls.run(options, ARGV) end
usage(msg)
click to toggle source
# File lib/pedant/cli.rb, line 86 def self.usage(msg) puts Rainbow(msg).color(:red) puts puts @@optparse exit 1 end