Sha256: 2790dbcd637c99c1dddd6b2058ffa697545cc8ded4b0003e29c0138a8ef9bec6
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
require 'optparse' $prog = File.basename($0) op = OptionParser.new op.banner = <<EOF usage: #{$prog} [options] COMMAND [args] options: EOF op.summary_indent = " " (class<<self;self;end).module_eval do define_method(:usage) do |errmsg| require 'td/command/list' puts op.to_s puts "" puts "commands:" puts TD::Command::List.help(op.summary_indent) puts "" puts "Type 'td help COMMAND' for more information on a specific command." if errmsg puts "error: #{errmsg}" exit 1 else exit 0 end end end config_path = File.join(ENV['HOME'], '.td', 'td.conf') $verbose = false #$debug = false op.on('-c', '--config PATH', "path to config file (~/.td/td.conf)") {|s| config_path = s } op.on('-v', '--verbose', "verbose mode", TrueClass) {|b| $verbose = b } #op.on('-d', '--debug', "debug mode", TrueClass) {|b| # $debug = b #} begin op.order!(ARGV) usage nil if ARGV.empty? cmd = ARGV.shift $TRD_CONFIG_PATH = config_path rescue usage $!.to_s end require 'td/command/list' method = TD::Command::List.get_method(cmd) unless method $stderr.puts "'#{cmd}' is not a td command. Run '#{$prog}' to show the list." TD::Command::List.show_guess(cmd) exit 1 end require 'td/error' begin method.call rescue TD::ConfigError $stderr.puts "TreasureData account is not configured yet." $stderr.puts "Run '#{$prog} account' first." rescue $stderr.puts "error #{$!.class}: backtrace:" $!.backtrace.each {|b| $stderr.puts " #{b}" } puts "" puts $! end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
td-0.7.1 | lib/td/command/td.rb |
td-0.7.0 | lib/td/command/td.rb |