Sha256: 37d6893054fcff4d56aad4ccf3682e3776a08a620f3f001adaa55de9afdf5dbc
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
require 'trollop' module Rbcli::Parser @cliopts = nil def self.parse @cliopts = Trollop::options do data = Rbcli.configuration version "#{data[:scriptname]} version: #{data[:version]}" banner <<-EOS #{data[:description]} For more information on individual commands, run `#{data[:scriptname]} <command> -h`. Usage: #{data[:scriptname]} [options] command [parameters] Commands: #{Rbcli::Command.descriptions 6, 21} [options]: EOS data[:options].each do |name, opts| opt name.to_sym, opts[:description], type: opts[:type], default: opts[:default] end opt :json_output, 'Output result in machine-friendly JSON format', :type => :boolean, :default => false if data[:allow_json] opt :config_file, 'Specify a config file manually', :type => :string, :default => data[:config_userfile] opt :generate_config, 'Generate a new config file' #defaults to false stop_on Rbcli::Command.commands.keys end @cmd = [ARGV.shift] # get the subcommand if @cliopts[:generate_config] Rbcli::Config::generate_userconf @cliopts[:config_file] puts "User config generated at #{@cliopts[:config_file]} using default values." elsif @cmd[0].nil? if Rbcli.configuration[:default_action].nil? Trollop::educate else Rbcli.configuration[:default_action].call @cliopts end elsif Rbcli::Command.commands.key? @cmd[0] @cmd << Rbcli::Command.commands[@cmd[0]].parseopts Rbcli.configuration[:pre_hook].call @cliopts unless Rbcli.configuration[:pre_hook].nil? Rbcli::Command.runcmd(@cmd.shift, @cmd[0], @cliopts) Rbcli.configuration[:post_hook].call @cliopts unless Rbcli.configuration[:pre_hook].nil? else Trollop::die "Unknown subcommand #{@cmd[0].inspect}" end end def self.opts @cliopts end def self.cmd @cmd end end module Rbcli def self.parse Rbcli::Parser::parse end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rbcli-0.1.1 | lib/rbcli/engine/parser.rb |
rbcli-0.1.0 | lib/rbcli/engine/parser.rb |