Class: Ecb
Constant Summary collapse
- CMD =
"ecb"
Instance Method Summary collapse
-
#define_sub_commands ⇒ Object
define sub commands here.
- #force_fail(cmd = nil) ⇒ Object
-
#options ⇒ Object
the options that were set.
- #parse ⇒ Object
- #print_actions ⇒ Object
- #printer ⇒ Object
-
#required_options ⇒ Object
required options.
- #run(argv = ARGV) ⇒ Object
- #setup ⇒ Object
- #sub_commands ⇒ Object
-
#validate(cmd, sub_cmd) ⇒ Object
validate the options passed.
Instance Method Details
#define_sub_commands ⇒ Object
define sub commands here
44 45 46 47 48 49 50 51 52 |
# File 'lib/ecb.rb', line 44 def define_sub_commands sub_commands[:version] = Commands::Version.new sub_commands[:randombranch] = Commands::RandomBranch.new sub_commands[:update_plist] = Commands::UpdatePlist.new sub_commands[:xcode_build] = Commands::XcodeBuild.new sub_commands[:shell] = Commands::Shell.new sub_commands[:promote] = Commands::Promote.new sub_commands[:verify_provision] = Commands::VerifyProvision.new end |
#force_fail(cmd = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/ecb.rb', line 79 def force_fail(cmd = nil) # force failure and show options ARGV.clear ARGV << "help" ARGV << cmd unless cmd.nil? opt_parse end |
#options ⇒ Object
the options that were set
31 32 33 |
# File 'lib/ecb.rb', line 31 def @options ||= {} end |
#parse ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ecb.rb', line 104 def parse if ARGV.empty? ARGV << "help" end cmd = opt_parse() if cmd.nil? force_fail end # ok, we have a valid command so dispatch it # puts "cmd: #{cmd}" # puts "options ......" # p options # puts "ARGV:" # p ARGV sub_cmd = sub_commands[cmd.to_sym] validate(cmd, sub_cmd) # track both types of options EcbSharedLib::Options. = EcbSharedLib::Options. = sub_cmd. sub_cmd.send("run", ) end |
#print_actions ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ecb.rb', line 152 def print_actions cmdtext = "Commands are:" @commands.sort.map do |c, opt| puts "inside opt.call loop" desc = opt.call.description unless c == "remove_merged_branches" cmdtext << "\n #{c} : #{desc}" end end # print aliases unless @aliases.empty? cmdtext << "\n\nAliases: \n" @aliases.each_pair { |name, val| cmdtext << " #{name} - #{val}\n" } end cmdtext end |
#printer ⇒ Object
39 40 41 |
# File 'lib/ecb.rb', line 39 def printer EcbSharedLib.printer end |
#required_options ⇒ Object
required options
26 27 28 |
# File 'lib/ecb.rb', line 26 def @required_options ||= Set.new [] end |
#run(argv = ARGV) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ecb.rb', line 132 def run(argv = ARGV) exit_code = true begin setup parse rescue SystemExit => ex # ignore direct calls to exit rescue Exception => ex printer.error printer.color(ex., :red) # puts ex.backtrace exit_code = false end # make sure buffer is flushed # debugger doesn't seem to do this always STDOUT.flush return exit_code end |
#setup ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ecb.rb', line 54 def setup .clear # global options do |opts| opts. = "Version: #{Info.version} - Usage: #{CMD} [options] [subcommand [options]]" opts.description = "eBay Mobile configuration and deploy tool. You must specify a valid sub command." opts.separator "" opts.separator "Global options are:" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| [:verbose] = v end end add_help_option define_sub_commands sub_commands.each_pair do |command_name, sub_cmd| command command_name do |opts| sub_cmd.send("register", opts, ) end end end |
#sub_commands ⇒ Object
35 36 37 |
# File 'lib/ecb.rb', line 35 def sub_commands @sub_commands ||= {} end |
#validate(cmd, sub_cmd) ⇒ Object
validate the options passed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ecb.rb', line 88 def validate(cmd, sub_cmd) .each do |r| if .has_key?(r) == false puts "Missing options" force_fail end end sub_cmd..each do |r| if sub_cmd..has_key?(r) == false puts "Missing options" force_fail(cmd) end end end |