ecb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,169 @@
1
+ #
2
+ # Greg Seitz
3
+ #
4
+ # Copyright 2013, eBay Inc.
5
+ # All rights reserved.
6
+ # http://www.ebay.com
7
+ #
8
+
9
+ require "fileutils"
10
+ require "pathname"
11
+ require 'plist'
12
+
13
+ $:.unshift(File.dirname(__FILE__))
14
+ models = File.expand_path('../../models', __FILE__)
15
+ $:.unshift(models)
16
+ require 'subcommand'
17
+ require 'commands'
18
+ require 'json/pure'
19
+ require 'info'
20
+
21
+ class Ecb
22
+ include Subcommands
23
+
24
+ CMD = "ecb"
25
+
26
+ # required options
27
+ def required_options
28
+ @required_options ||= Set.new []
29
+ end
30
+
31
+ # the options that were set
32
+ def options
33
+ @options ||= {}
34
+ end
35
+
36
+ def sub_commands
37
+ @sub_commands ||= {}
38
+ end
39
+
40
+ def printer
41
+ EbmSharedLib.printer
42
+ end
43
+
44
+ # define sub commands here
45
+ def define_sub_commands
46
+ sub_commands[:version] = Commands::Version.new
47
+ sub_commands[:randombranch] = Commands::RandomBranch.new
48
+ sub_commands[:update_plist] = Commands::UpdatePlist.new
49
+ end
50
+
51
+ def setup
52
+ options.clear
53
+ # global options
54
+ global_options do |opts|
55
+ opts.banner = "Version: #{Info.version} - Usage: #{CMD} [options] [subcommand [options]]"
56
+ opts.description = "eBay Mobile configuration and deploy tool. You must specify a valid sub command."
57
+ opts.separator ""
58
+ opts.separator "Global options are:"
59
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
60
+ options[:verbose] = v
61
+ end
62
+
63
+ end
64
+ add_help_option
65
+
66
+ define_sub_commands
67
+
68
+ sub_commands.each_pair do |command_name, sub_cmd|
69
+ command command_name do |opts|
70
+ sub_cmd.send("register", opts, options)
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ def force_fail(cmd = nil)
77
+ # force failure and show options
78
+ ARGV.clear
79
+ ARGV << "help"
80
+ ARGV << cmd unless cmd.nil?
81
+ opt_parse
82
+ end
83
+
84
+ # validate the options passed
85
+ def validate(cmd, sub_cmd)
86
+ required_options.each do |r|
87
+ if options.has_key?(r) == false
88
+ puts "Missing options"
89
+ force_fail
90
+ end
91
+ end
92
+
93
+ sub_cmd.required_options.each do |r|
94
+ if sub_cmd.options.has_key?(r) == false
95
+ puts "Missing options"
96
+ force_fail(cmd)
97
+ end
98
+ end
99
+ end
100
+
101
+ def parse
102
+ if ARGV.empty?
103
+ ARGV << "help"
104
+ end
105
+
106
+ cmd = opt_parse()
107
+ if cmd.nil?
108
+ force_fail
109
+ end
110
+
111
+ # ok, we have a valid command so dispatch it
112
+ # puts "cmd: #{cmd}"
113
+ # puts "options ......"
114
+ # p options
115
+ # puts "ARGV:"
116
+ # p ARGV
117
+
118
+ sub_cmd = sub_commands[cmd.to_sym]
119
+ validate(cmd, sub_cmd)
120
+
121
+ # track both types of options
122
+ EbmSharedLib::Options.global_options = options
123
+ EbmSharedLib::Options.cmd_options = sub_cmd.options
124
+
125
+ sub_cmd.send("run", options)
126
+ end
127
+
128
+
129
+
130
+ def run(argv = ARGV)
131
+ exit_code = true
132
+ begin
133
+ setup
134
+ parse
135
+ rescue SystemExit => ex
136
+ # ignore direct calls to exit
137
+ rescue Exception => ex
138
+ printer.error printer.color(ex.message, :red)
139
+ # puts ex.backtrace
140
+ exit_code = false
141
+ end
142
+
143
+ # make sure buffer is flushed
144
+ # debugger doesn't seem to do this always
145
+ STDOUT.flush
146
+
147
+ return exit_code
148
+ end
149
+
150
+ def print_actions
151
+ cmdtext = "Commands are:"
152
+ @commands.sort.map do |c, opt|
153
+ puts "inside opt.call loop"
154
+ desc = opt.call.description
155
+ unless c == "remove_merged_branches"
156
+ cmdtext << "\n #{c} : #{desc}"
157
+ end
158
+ end
159
+
160
+ # print aliases
161
+ unless @aliases.empty?
162
+ cmdtext << "\n\nAliases: \n"
163
+ @aliases.each_pair { |name, val| cmdtext << " #{name} - #{val}\n" }
164
+ end
165
+
166
+ cmdtext
167
+ end
168
+
169
+ end
@@ -0,0 +1,12 @@
1
+ #
2
+ # Greg Seitz
3
+ #
4
+ # Copyright 2013, eBay Inc.
5
+ # All rights reserved.
6
+ # http://www.ebay.com
7
+ #
8
+ class Info
9
+ def self.version
10
+ "0.0.1"
11
+ end
12
+ end
@@ -0,0 +1,61 @@
1
+ #
2
+ # Greg Seitz
3
+ #
4
+ # Copyright 2013, eBay Inc.
5
+ # All rights reserved.
6
+ # http://www.ebay.com
7
+ #
8
+ class Printer
9
+ attr_reader :stdout
10
+ attr_reader :stderr
11
+ attr_reader :stdin
12
+
13
+ def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN)
14
+ @stdout, @stderr, @stdin = stdout, stderr, stdin
15
+ end
16
+
17
+ def highline
18
+ @highline ||= begin
19
+ require 'highline'
20
+ HighLine.new
21
+ end
22
+ end
23
+
24
+ # Prints a message to stdout. Aliased as +info+ for compatibility with
25
+ # the logger API.
26
+ def msg(message)
27
+ stdout.puts message
28
+ stdout.flush
29
+ end
30
+
31
+ alias :info :msg
32
+
33
+ # Print a warning message
34
+ def warn(message)
35
+ msg("#{color('WARNING:', :yellow, :bold)} #{message}")
36
+ end
37
+
38
+ # Print an error message
39
+ def error(message)
40
+ msg("#{color('ERROR:', :red, :bold)} #{message}")
41
+ end
42
+
43
+ # Print a message describing a fatal error.
44
+ def fatal(message)
45
+ msg("#{color('FATAL:', :red, :bold)} #{message}")
46
+ end
47
+
48
+ def color(string, *colors)
49
+ if color?
50
+ highline.color(string, *colors)
51
+ else
52
+ string
53
+ end
54
+ end
55
+
56
+ # Should colored output be used? Only on TTY
57
+ def color?
58
+ true
59
+ end
60
+
61
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ecb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rick Hoiberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: subcommand
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json_pure
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-hmac
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: highline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.12
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.12
69
+ description: Various utility commands for building eBay mobile Core
70
+ email:
71
+ executables:
72
+ - ecb
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/commands/commit.rb
77
+ - lib/commands/configs.rb
78
+ - lib/commands/format_helper.rb
79
+ - lib/commands/make_sample.rb
80
+ - lib/commands/periodic.rb
81
+ - lib/commands/prepare.rb
82
+ - lib/commands/prune.rb
83
+ - lib/commands/pull.rb
84
+ - lib/commands/push.rb
85
+ - lib/commands/randombranch.rb
86
+ - lib/commands/remove_merged_branches.rb
87
+ - lib/commands/tag.rb
88
+ - lib/commands/update_plist.rb
89
+ - lib/commands/version.rb
90
+ - lib/commands.rb
91
+ - lib/ebmsharedlib/monkey_patches.rb
92
+ - lib/ebmsharedlib/options.rb
93
+ - lib/ebmsharedlib/utilities.rb
94
+ - lib/ecb.rb
95
+ - lib/info.rb
96
+ - lib/printer.rb
97
+ - bin/ecb
98
+ - LICENSE
99
+ homepage:
100
+ licenses: []
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options:
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ - lib/commands
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '1.8'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.3
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Core Builder
124
+ test_files: []