branch_io_cli 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d6d029c93a40885ef2c8f619c45d550cd49a680
4
- data.tar.gz: 3553f1e6241a02f8329f30d4ac9ab65057a78ac0
3
+ metadata.gz: 5010d2220f3412bda298fa667173dd26b6142f20
4
+ data.tar.gz: 91b25b66bd4c3d4b9e6bf9ea9051763c5bd5cc01
5
5
  SHA512:
6
- metadata.gz: 738daf6516afbdde4902e7be83865a856031b28b565d07d1c244b5c53cc817795d3a20ecf48c2ebf9f52f306903405fbdc4784039d6b25625d4109858c3a1c3f
7
- data.tar.gz: e861e2ceb053c93cf2ab57605856386e07767f8c36b683cb4387b3fd118cc882026a24a41d436e3840bbd13e20155df025612128771f56d2e85e97638bd75f2f
6
+ metadata.gz: 3bffd545175fc581e8ae95b7ea13002386a36c994fbff76169538d2ee4cb047b10ea4b41457526b707bab99755763bf6a3589ab91086da68578f882a79676df4
7
+ data.tar.gz: 07af2fa0b8aad5aec93df27be95a4707c58b196f5f761b1c1f276ec80c0a51974f21cb2f5d5ad84c1ec16c1c2f73f06d72d9435debb7d0ffc7910332b392a5da
data/README.md CHANGED
@@ -229,7 +229,8 @@ report with additional diagnostic information suitable for opening a support tic
229
229
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project|
230
230
  |--target MyAppTarget|Name of a target to modify in the Xcode project|
231
231
  |--scheme MyAppScheme|Name of a scheme to build|
232
- |--configuration Debug/Release/CustomConfig|Name of a build configuration|
232
+ |--configuration Debug/Release/CustomConfig|Name of a build configuration (default: Release)|
233
+ |--sdk iphonesimulator|Name of an SDK to use with xcodebuild (default: iphonesimulator)|
233
234
  |--[no-]clean|Clean before building (default: yes)|
234
235
  |--[no-]header-only|Show a diagnostic header and exit without cleaning or building (default: no)|
235
236
  |--podfile /path/to/Podfile|Path to the Podfile for the project|
@@ -163,6 +163,7 @@ EOF
163
163
  c.option "--scheme MyProjectScheme", String, "A scheme from the project or workspace to build"
164
164
  c.option "--target MyProjectTarget", String, "A target to build"
165
165
  c.option "--configuration Debug|Release|CustomConfigName", String, "The build configuration to use (default: Release)"
166
+ c.option "--sdk iphonesimulator", String, "Passed as -sdk to xcodebuild (default: iphonesimulator)"
166
167
  c.option "--podfile /path/to/Podfile", String, "Path to the Podfile for the project"
167
168
  c.option "--cartfile /path/to/Cartfile", String, "Path to the Cartfile for the project"
168
169
  c.option "--[no-]clean", "Clean before attempting to build (default: yes)"
@@ -170,7 +171,12 @@ EOF
170
171
  c.option "--out branch-report.txt", String, "Report output path (default: ./branch-report.txt)"
171
172
 
172
173
  c.action do |args, options|
173
- options.default clean: true, header_only: false
174
+ options.default(
175
+ clean: true,
176
+ header_only: false,
177
+ configuration: "Release",
178
+ sdk: "iphonesimulator"
179
+ )
174
180
  Commands::ReportCommand.new(options).run!
175
181
  end
176
182
  end
@@ -18,34 +18,52 @@ module BranchIOCLI
18
18
 
19
19
  File.open config_helper.report_path, "w" do |report|
20
20
  report.write "Branch.io Xcode build report v #{VERSION} #{DateTime.now}\n\n"
21
- # TODO: Write out command-line options or configuration from helper
21
+ report.write "#{report_configuration}\n"
22
22
  report.write "#{report_header}\n"
23
23
 
24
+ # run xcodebuild -list
24
25
  report.report_command "#{base_xcodebuild_cmd} -list"
25
- report.report_command "#{base_xcodebuild_cmd} -showBuildSettings"
26
+
27
+ # If using a workspace, -list all the projects as well
28
+ if config_helper.workspace_path
29
+ config_helper.workspace.file_references.map(&:path).each do |project_path|
30
+ path = File.join File.dirname(config_helper.workspace_path), project_path
31
+ report.report_command "xcodebuild -list -project #{path}"
32
+ end
33
+ end
34
+
35
+ base_cmd = base_xcodebuild_cmd
36
+ # Add -scheme option for the rest of the commands if using a workspace
37
+ base_cmd = "#{base_cmd} -scheme #{config_helper.scheme}" if config_helper.workspace_path
38
+
39
+ # xcodebuild -showBuildSettings
40
+ report.report_command "#{base_cmd} -showBuildSettings"
41
+
42
+ # Add more options for the rest of the commands
43
+ base_cmd = "#{base_cmd} -configuration #{config_helper.configuration} -sdk #{config_helper.sdk}"
44
+ base_cmd = "#{base_cmd} -target #{config_helper.target}" unless config_helper.workspace_path
26
45
 
27
46
  if config_helper.clean
28
47
  say "Cleaning"
29
- report.report_command "#{base_xcodebuild_cmd} clean"
48
+ report.report_command "#{base_cmd} clean"
30
49
  end
31
50
 
32
51
  say "Building"
33
- report.report_command "#{base_xcodebuild_cmd} -verbose"
52
+ report.report_command "#{base_cmd} -verbose"
34
53
 
35
54
  say "Done ✅"
36
55
  end
37
- @report = nil
38
56
 
39
57
  say "Report generated in #{config_helper.report_path}"
40
58
  end
41
59
 
42
60
  def base_xcodebuild_cmd
43
- cmd = "xcodebuild -sdk iphonesimulator"
44
- cmd = "#{cmd} -scheme #{config_helper.scheme}" if config_helper.scheme
45
- cmd = "#{cmd} -workspace #{config_helper.workspace_path}" if config_helper.workspace_path
46
- cmd = "#{cmd} -project #{config_helper.xcodeproj_path}" if config_helper.xcodeproj_path && !config_helper.workspace_path
47
- cmd = "#{cmd} -target #{config_helper.target}" if config_helper.target
48
- cmd = "#{cmd} -configuration #{config_helper.configuration}" if config_helper.configuration
61
+ cmd = "xcodebuild"
62
+ if config_helper.workspace_path
63
+ cmd = "#{cmd} -workspace #{config_helper.workspace_path}"
64
+ else
65
+ cmd = "#{cmd} -project #{config_helper.xcodeproj_path}"
66
+ end
49
67
  cmd
50
68
  end
51
69
 
@@ -66,7 +84,7 @@ module BranchIOCLI
66
84
  def requirement_from_cartfile
67
85
  return nil unless config_helper.cartfile_path
68
86
  cartfile = File.read config_helper.cartfile_path
69
- matches = %r{\n?[^\n]+?BranchMetrics/(ios-branch-deep-linking|iOS-Deferred-Deep-Linking-SDK.*?).*?\n}m.match cartfile
87
+ matches = %r{^git(hub\s+"|\s+"https://github.com/)BranchMetrics/(ios-branch-deep-linking|iOS-Deferred-Deep-Linking-SDK.*?).*?\n}m.match cartfile
70
88
  matches ? matches[0].strip : nil
71
89
  end
72
90
 
@@ -98,9 +116,9 @@ module BranchIOCLI
98
116
  end
99
117
 
100
118
  def version_from_branch_framework
101
- framework = config_helper.xcodeproj.frameworks_group.files.find { |f| f.path =~ /Branch.framework$/ }
119
+ framework = config_helper.target.frameworks_build_phase.files.find { |f| f.file_ref.path =~ /Branch.framework$/ }
102
120
  return nil unless framework
103
- framework_path = framework.real_path
121
+ framework_path = framework.file_ref.real_path
104
122
  info_plist_path = File.join framework_path.to_s, "Info.plist"
105
123
  return nil unless File.exist? info_plist_path
106
124
 
@@ -123,29 +141,91 @@ module BranchIOCLI
123
141
  "#{version} [BNCConfig.m]"
124
142
  end
125
143
 
144
+ def report_configuration
145
+ <<EOF
146
+ Configuration:
147
+
148
+ Xcode workspace: #{config_helper.workspace_path || '(none)'}
149
+ Xcode project: #{config_helper.xcodeproj_path || '(none)'}
150
+ Scheme: #{config_helper.scheme || '(none)'}
151
+ Target: #{config_helper.target || '(none)'}
152
+ Configuration: #{config_helper.configuration || '(none)'}
153
+ SDK: #{config_helper.sdk}
154
+ Podfile: #{config_helper.podfile_path || '(none)'}
155
+ Cartfile: #{config_helper.cartfile_path || '(none)'}
156
+ Clean: #{config_helper.clean.inspect}
157
+ EOF
158
+ end
159
+
160
+ # rubocop: disable Metrics/PerceivedComplexity
126
161
  def report_header
127
162
  header = `xcodebuild -version`
128
163
 
129
- if config_helper.podfile_path && File.exist?("#{config_helper.podfile_path}.lock")
130
- podfile_lock = Pod::Lockfile.from_file Pathname.new "#{config_helper.podfile_path}.lock"
131
- header = "#{header}\nUsing CocoaPods v. #{podfile_lock.cocoapods_version}\n"
164
+ header += "\nTarget #{config_helper.target.name} deploy target: #{config_helper.target.deployment_target}\n"
165
+
166
+ if config_helper.podfile_path
167
+ begin
168
+ cocoapods_version = `pod --version`.chomp
169
+ rescue Errno::ENOENT
170
+ header += "\n(pod command not found)\n"
171
+ end
172
+
173
+ if File.exist?("#{config_helper.podfile_path}.lock")
174
+ podfile_lock = Pod::Lockfile.from_file Pathname.new "#{config_helper.podfile_path}.lock"
175
+ end
176
+
177
+ if cocoapods_version || podfile_lock
178
+ header += "\nUsing CocoaPods v. "
179
+ if cocoapods_version
180
+ header += "#{cocoapods_version} (CLI) "
181
+ end
182
+ if podfile_lock
183
+ header += "#{podfile_lock.cocoapods_version} (Podfile.lock)"
184
+ end
185
+ header += "\n"
186
+ end
187
+
188
+ # Already verified existence.
189
+ podfile = Pod::Podfile.from_file Pathname.new config_helper.podfile_path
190
+ target_definition = podfile.target_definition_list.find { |t| t.name == config_helper.target.name }
191
+ if target_definition
192
+ branch_dep = target_definition.dependencies.find { |p| p.name == "Branch" }
193
+ header += "Podfile target #{target_definition.name}:"
194
+ header += "\n use_frameworks!" if target_definition.uses_frameworks?
195
+ header += "\n platform: #{target_definition.platform}"
196
+ header += "\n build configurations: #{target_definition.build_configurations}"
197
+ header += "\n inheritance: #{target_definition.inheritance}"
198
+ header += "\n pod 'Branch', '#{branch_dep.requirement}'" if branch_dep
199
+ header += ", #{branch_dep.external_source}" if branch_dep && branch_dep.external_source
200
+ header += "\n"
201
+ else
202
+ header += "Target #{config_helper.target.name.inspect} not found in Podfile.\n"
203
+ end
204
+
132
205
  end
133
206
 
134
- podfile_requirement = requirement_from_podfile
135
- header = "#{header}\nFrom Podfile:\n#{podfile_requirement}\n" if podfile_requirement
207
+ if config_helper.cartfile_path
208
+ begin
209
+ carthage_version = `carthage version`.chomp
210
+ header += "\nUsing Carthage v. #{carthage_version}\n"
211
+ rescue Errno::ENOENT
212
+ header += "\n(carthage command not found)\n"
213
+ end
214
+ end
136
215
 
137
216
  cartfile_requirement = requirement_from_cartfile
138
- header = "#{header}\nFrom Cartfile:\n#{cartfile_requirement}\n" if cartfile_requirement
217
+ header += "\nFrom Cartfile:\n#{cartfile_requirement}\n" if cartfile_requirement
139
218
 
140
219
  version = branch_version
141
220
  if version
142
- header = "#{header}\nBranch SDK v. #{version}\n"
221
+ header += "\nBranch SDK v. #{version}\n"
143
222
  else
144
- header = "Branch SDK not found.\n"
223
+ header += "\nBranch SDK not found.\n"
145
224
  end
146
225
 
147
226
  header
148
227
  end
228
+ # rubocop: enable Metrics/PerceivedComplexity
149
229
  end
150
230
  end
151
231
  end
@@ -1,3 +1,5 @@
1
+ require "branch_io_cli/helper/methods"
2
+
1
3
  module BranchIOCLI
2
4
  module Commands
3
5
  class SetupCommand < Command
@@ -46,7 +48,7 @@ module BranchIOCLI
46
48
  helper.ensure_uri_scheme_in_info_plist if is_app_target # does nothing if already present
47
49
 
48
50
  new_path = helper.add_universal_links_to_project @domains, false if is_app_target
49
- `git add #{new_path}` if options.commit && new_path
51
+ sh "git add #{new_path}" if options.commit && new_path
50
52
 
51
53
  config_helper.target.add_system_frameworks options.frameworks unless options.frameworks.nil? || options.frameworks.empty?
52
54
 
@@ -58,7 +60,7 @@ module BranchIOCLI
58
60
 
59
61
  changes = helper.changes.to_a.map { |c| Pathname.new(File.expand_path(c)).relative_path_from(Pathname.pwd).to_s }
60
62
 
61
- `git commit #{changes.join(" ")} -m '[branch_io_cli] Branch SDK integration'`
63
+ sh "git commit -qm '[branch_io_cli] Branch SDK integration' #{changes.join(' ')}"
62
64
  end
63
65
  # rubocop: enable Metrics/PerceivedComplexity
64
66
  end
@@ -33,8 +33,8 @@ end
33
33
  #
34
34
  # :command: [String] a shell command to execute and report
35
35
  def STDOUT.report_command(command)
36
- # TODO: Improve this?
37
- say "<%= color('$ #{command}', BOLD) %>\n\n"
36
+ # TODO: Improve this implementation?
37
+ say "<%= color(%q{$ #{command}}, [MAGENTA, BOLD]) %>\n\n"
38
38
  # May also write to stderr
39
39
  # Could try system "#{command} 2>&1", but that might depend on the shell.
40
40
  system command
@@ -45,4 +45,5 @@ def STDOUT.report_command(command)
45
45
  else
46
46
  write "#{status}\n\n"
47
47
  end
48
+ status
48
49
  end
@@ -1,3 +1,2 @@
1
1
  require "branch_io_cli/helper/branch_helper"
2
2
  require "branch_io_cli/helper/configuration_helper"
3
- require "branch_io_cli/helper/methods"
@@ -41,6 +41,7 @@ module BranchIOCLI
41
41
  attr_reader :scheme
42
42
  attr_reader :configuration
43
43
  attr_reader :report_path
44
+ attr_reader :sdk
44
45
 
45
46
  def validate_setup_options(options)
46
47
  print_identification "setup"
@@ -100,8 +101,10 @@ module BranchIOCLI
100
101
  @target = options.target
101
102
  @configuration = options.configuration
102
103
  @report_path = options.out || "./report.txt"
104
+ @sdk = options.sdk
103
105
 
104
106
  validate_xcodeproj_and_workspace options
107
+ validate_target options
105
108
  validate_scheme options
106
109
 
107
110
  # If neither --podfile nor --cartfile is present, arbitrarily look for a Podfile
@@ -127,7 +130,7 @@ EOF
127
130
 
128
131
  def print_setup_configuration
129
132
  say <<EOF
130
- <%= color('Configuration:', BOLD) %>
133
+ <%= color('Configuration:', [CYAN, BOLD, UNDERLINE]) %>
131
134
 
132
135
  <%= color('Xcode project:', BOLD) %> #{@xcodeproj_path}
133
136
  <%= color('Target:', BOLD) %> #{@target.name}
@@ -151,7 +154,7 @@ EOF
151
154
 
152
155
  def print_validation_configuration
153
156
  say <<EOF
154
- <%= color('Configuration:', BOLD) %>
157
+ <%= color('Configuration:', [CYAN, BOLD, UNDERLINE]) %>
155
158
 
156
159
  <%= color('Xcode project:', BOLD) %> #{@xcodeproj_path}
157
160
  <%= color('Target:', BOLD) %> #{@target.name}
@@ -161,13 +164,14 @@ EOF
161
164
 
162
165
  def print_report_configuration
163
166
  say <<EOF
164
- <%= color('Configuration:', BOLD) %>
167
+ <%= color('Configuration:', [CYAN, BOLD, UNDERLINE]) %>
165
168
 
166
169
  <%= color('Xcode workspace:', BOLD) %> #{@workspace_path || '(none)'}
167
170
  <%= color('Xcode project:', BOLD) %> #{@xcodeproj_path || '(none)'}
168
171
  <%= color('Scheme:', BOLD) %> #{@scheme || '(none)'}
169
172
  <%= color('Target:', BOLD) %> #{@target || '(none)'}
170
- <%= color('Configuration:', BOLD) %> #{@configuration || '(none)'}
173
+ <%= color('Configuration:', BOLD) %> #{@configuration}
174
+ <%= color('SDK:', BOLD) %> #{@sdk}
171
175
  <%= color('Podfile:', BOLD) %> #{@podfile_path || '(none)'}
172
176
  <%= color('Cartfile:', BOLD) %> #{@cartfile_path || '(none)'}
173
177
  <%= color('Clean:', BOLD) %> #{@clean.inspect}
@@ -337,11 +341,15 @@ EOF
337
341
 
338
342
  def validate_scheme(options)
339
343
  schemes = all_schemes
344
+ # TODO: Prompt if --scheme specified but not found.
340
345
  if options.scheme && schemes.include?(options.scheme)
341
346
  @scheme = options.scheme
342
347
  elsif schemes.count == 1
343
348
  @scheme = schemes.first
344
349
  elsif !schemes.empty?
350
+ # By default, take a scheme with the same name as the target name.
351
+ return if (@scheme = schemes.find { |s| s == @target.name })
352
+
345
353
  say "Please specify one of the following for the --scheme argument:"
346
354
  schemes.each do |scheme|
347
355
  say " #{scheme}"
@@ -11,8 +11,6 @@ require "branch_io_cli/helper/methods"
11
11
  module BranchIOCLI
12
12
  module Helper
13
13
  module IOSHelper
14
- include Methods
15
-
16
14
  APPLINKS = "applinks"
17
15
  ASSOCIATED_DOMAINS = "com.apple.developer.associated-domains"
18
16
  CODE_SIGN_ENTITLEMENTS = "CODE_SIGN_ENTITLEMENTS"
@@ -341,7 +339,8 @@ module BranchIOCLI
341
339
  raise "Target #{target} not found" if target.nil?
342
340
  else
343
341
  # find the first application target
344
- target = project.targets.find { |t| !t.extension_target_type? && !t.test_target_type? }
342
+ targets = project.targets.select { |t| !t.extension_target_type? && !t.test_target_type? }
343
+ target = targets.find { |t| t.name == File.basename(project.path).sub(/\.xcodeproj$/, "") } || targets.first
345
344
  raise "No application target found" if target.nil?
346
345
  end
347
346
  target
@@ -793,7 +792,7 @@ EOF
793
792
  install_command = "pod install"
794
793
  install_command += " --repo-update" if options.pod_repo_update
795
794
  Dir.chdir(File.dirname(podfile_path)) do
796
- report_command "pod init"
795
+ sh "pod init"
797
796
  apply_patch(
798
797
  files: podfile_path,
799
798
  regexp: /^(\s*)# Pods for #{ConfigurationHelper.target.name}$/,
@@ -801,7 +800,7 @@ EOF
801
800
  text: "\n\\1pod \"Branch\"",
802
801
  global: false
803
802
  )
804
- report_command install_command
803
+ sh install_command
805
804
  end
806
805
 
807
806
  add_change podfile_path
@@ -813,7 +812,7 @@ EOF
813
812
  podfile_pathname = Pathname.new(podfile_path).relative_path_from Pathname.pwd
814
813
  add_change pods_folder_path
815
814
  add_change workspace_path
816
- `git add #{podfile_pathname} #{podfile_pathname}.lock #{pods_folder_path} #{workspace_path}` if options.commit
815
+ sh "git add #{podfile_pathname} #{podfile_pathname}.lock #{pods_folder_path} #{workspace_path}" if options.commit
817
816
  end
818
817
 
819
818
  def add_carthage(options)
@@ -830,7 +829,7 @@ EOF
830
829
 
831
830
  # 2. carthage update
832
831
  Dir.chdir(File.dirname(cartfile_path)) do
833
- report_command "carthage #{ConfigurationHelper.carthage_command}"
832
+ sh "carthage #{ConfigurationHelper.carthage_command}"
834
833
  end
835
834
 
836
835
  # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
@@ -859,7 +858,7 @@ EOF
859
858
  carthage_folder_path = Pathname.new(File.expand_path("../Carthage", cartfile_path)).relative_path_from(Pathname.pwd)
860
859
  cartfile_pathname = Pathname.new(cartfile_path).relative_path_from Pathname.pwd
861
860
  add_change carthage_folder_path
862
- `git add #{cartfile_pathname} #{cartfile_pathname}.resolved #{carthage_folder_path}` if options.commit
861
+ sh "git add #{cartfile_pathname} #{cartfile_pathname}.resolved #{carthage_folder_path}" if options.commit
863
862
  end
864
863
 
865
864
  def add_direct(options)
@@ -923,7 +922,7 @@ EOF
923
922
 
924
923
  add_change ConfigurationHelper.xcodeproj_path
925
924
  add_change framework_path
926
- `git add #{framework_path}` if options.commit
925
+ sh "git add #{framework_path}" if options.commit
927
926
 
928
927
  say "Done. ✅"
929
928
  end
@@ -943,7 +942,7 @@ EOF
943
942
  command += ' --repo-update' if options.pod_repo_update
944
943
 
945
944
  Dir.chdir(File.dirname(podfile_path)) do
946
- report_command command
945
+ sh command
947
946
  end
948
947
 
949
948
  # 3. Add Podfile and Podfile.lock to commit (in case :commit param specified)
@@ -957,7 +956,7 @@ EOF
957
956
 
958
957
  # 5. If so, add the Pods folder to the commit (in case :commit param specified)
959
958
  add_change pods_folder_path
960
- `git add #{pods_folder_path}` if options.commit
959
+ sh "git add #{pods_folder_path}" if options.commit
961
960
 
962
961
  true
963
962
  end
@@ -973,7 +972,7 @@ EOF
973
972
 
974
973
  # 2. carthage update
975
974
  Dir.chdir(File.dirname(cartfile_path)) do
976
- report_command "carthage #{ConfigurationHelper.carthage_command}"
975
+ sh "carthage #{ConfigurationHelper.carthage_command}"
977
976
  end
978
977
 
979
978
  # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
@@ -1004,7 +1003,7 @@ EOF
1004
1003
 
1005
1004
  # 7. If so, add the Carthage folder to the commit (in case :commit param specified)
1006
1005
  add_change carthage_folder_path
1007
- `git add #{carthage_folder_path}` if options.commit
1006
+ sh "git add #{carthage_folder_path}" if options.commit
1008
1007
 
1009
1008
  true
1010
1009
  end
@@ -1031,13 +1030,13 @@ EOF
1031
1030
 
1032
1031
  gem_home = ENV["GEM_HOME"]
1033
1032
  if gem_home && File.writable?(gem_home)
1034
- report_command "gem install cocoapods"
1033
+ sh "gem install cocoapods"
1035
1034
  else
1036
- report_command "sudo gem install cocoapods"
1035
+ sh "sudo gem install cocoapods"
1037
1036
  end
1038
1037
 
1039
1038
  # Ensure master podspec repo is set up (will update if it exists).
1040
- report_command "pod setup"
1039
+ sh "pod setup"
1041
1040
  end
1042
1041
 
1043
1042
  def verify_carthage
@@ -1056,7 +1055,7 @@ EOF
1056
1055
  exit(-1)
1057
1056
  end
1058
1057
 
1059
- report_command "brew install carthage"
1058
+ sh "brew install carthage"
1060
1059
  end
1061
1060
 
1062
1061
  def verify_git
@@ -1077,7 +1076,7 @@ EOF
1077
1076
  exit(-1)
1078
1077
  end
1079
1078
 
1080
- report_command "xcode-select --install"
1079
+ sh "xcode-select --install"
1081
1080
  end
1082
1081
  end
1083
1082
  end
@@ -1,9 +1,25 @@
1
1
  module BranchIOCLI
2
2
  module Helper
3
+ class CommandError < RuntimeError; end
4
+
3
5
  module Methods
4
- def report_command(command)
5
- STDOUT.report_command command
6
+ # Execute a shell command with reporting.
7
+ # The command itself is logged, then output from
8
+ # both stdout and stderr, then a success or failure
9
+ # message. Raises CommandError on error.
10
+ #
11
+ # If output is STDOUT (the default), no redirection occurs. In all
12
+ # other cases, both stdout and stderr are redirected to output.
13
+ # In these cases, formatting (colors, highlights) may be lost.
14
+ #
15
+ # :command: [String] A shell command to execute
16
+ # :output: [IO] An optional IO object to receive stdout and stderr from the command
17
+ def sh(command, output = STDOUT)
18
+ status = output.report_command command
19
+ raise CommandError, %{Error executing "#{command}": #{status}.} unless status.success?
6
20
  end
7
21
  end
8
22
  end
9
23
  end
24
+
25
+ include BranchIOCLI::Helper::Methods
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branch_io_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branch
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-02 00:00:00.000000000 Z
12
+ date: 2017-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: CFPropertyList