class FlatKit::Cli
Attributes
options[R]
Public Class Methods
new()
click to toggle source
# File lib/flat_kit/cli.rb, line 8 def initialize @parser = nil end
Public Instance Methods
parser()
click to toggle source
# File lib/flat_kit/cli.rb, line 12 def parser @parser ||= ::Optimist::Parser.new do version ::FlatKit::VERSION banner "fk v#{self.version}" banner <<~USAGE Usage: fk <command> [<args>...] fk [options] USAGE banner <<~OPTIONS Options: OPTIONS opt :verbose, "Force debug. Output lots of informtion to standard error", default: false opt :list, "List all the commands", default: false, short: :none opt :log, "Set the logger output location", default: "<stderr>", short: :none opt :help, "Show help message", short: :h opt :version, "Print version and exit", short: :none stop_on FlatKit::Command.names banner Cli.commands_banner end end
run(argv: ARGV, env: ENV)
click to toggle source
# File lib/flat_kit/cli.rb, line 56 def run(argv: ARGV, env: ENV) opts = ::Optimist::with_standard_exception_handling(parser) do parser.parse(argv) end if opts[:log_given] then ::FlatKit.log_to(opts[:log]) end if opts[:verbose] then ::FlatKit.logger.level = :debug else ::FlatKit.logger.level = :info end ::FlatKit.logger.debug opts ::FlatKit.logger.debug argv command_name = argv.shift if command_name.downcase == "help" then parser.educate exit 0 end command_klass = FlatKit::Command.for(command_name) if command_klass.nil? then $stdout.puts "ERROR: Unknown command '#{command_name}'" parser.educate exit 0 end command = command_klass.new(argv: argv, logger: ::FlatKit.logger, env: env) command.call end