branch_io_cli 0.13.0 → 0.13.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 127f04c8e5422054f2eb24e0ef8c1e0b3a2f5c0e938f77f02ea3baa1d457b552
4
- data.tar.gz: 58d2336145b1f3683b91856711d94e81d9efe94e3d8dbdad782a254ab5b93db8
3
+ metadata.gz: d070eebc7fcafbeca391b9bd8e319b2dd204ea3e06b50e5c03d2140003251fc5
4
+ data.tar.gz: 901ecc88737470df07c08aff6a076ed210f109c6797d92e654ae2c730341d206
5
5
  SHA512:
6
- metadata.gz: 2c40028ed828ec0727d74b5dae8a53569eadd39cf163df4c7d254d9083ac40e945b281c2d5015928280fcaf9ebe3bb59661a39ab7a23afc8c7b20531635f256d
7
- data.tar.gz: 42d189d84f4218464ffe61dbc52eb66b8f342e4298d363776e56adad81339ba8de324787b99fe9df2be68b4471e08975e0a0ca1f775bb600b82b57db47df10aa
6
+ metadata.gz: ac7ca487cadb9cd19525381b88e9e994974a7693d306d2279e7b975c2aff778cdc1605b8d24f44a756e7afc9ea8cf92e3b45c5273d8944436316172c301b2bdc
7
+ data.tar.gz: 68f31555998ecfcfd1e2c36e59e939572304f5d8beb4b67de15f8a37bf6003731587448ade32f8fa0474dbebfec37cd503b04d89dd1d6aa085fb3f8dd24eb9d9
data/README.md CHANGED
@@ -38,6 +38,7 @@ branch_io -h
38
38
  branch_io setup -h
39
39
  branch_io validate -h
40
40
  branch_io report -h
41
+ branch_io env -h
41
42
  ```
42
43
 
43
44
  The gem also installs `br` as an alias for `branch_io`:
@@ -47,6 +48,7 @@ br -h
47
48
  br setup -h
48
49
  br validate -h
49
50
  br report -h
51
+ br env -h
50
52
  ```
51
53
 
52
54
  ### Shell completion
@@ -1,5 +1,5 @@
1
1
  require "active_support/core_ext/hash"
2
- require "json"
2
+ require "active_support/json"
3
3
  require_relative "helper"
4
4
  require "tty/spinner"
5
5
 
@@ -1,4 +1,5 @@
1
1
  require "shellwords"
2
+ require "tty/spinner"
2
3
 
3
4
  module BranchIOCLI
4
5
  module Command
@@ -6,14 +7,17 @@ module BranchIOCLI
6
7
  def run!
7
8
  say "\n"
8
9
 
9
- say "Loading settings from Xcode"
10
+ task = Helper::Task.new
11
+ task.begin "Loading settings from Xcode."
12
+
10
13
  # In case running in a non-CLI context (e.g., Rake or Fastlane) be sure
11
14
  # to reset Xcode settings each time, since project, target and
12
15
  # configurations will change.
13
16
  Configuration::XcodeSettings.reset
14
17
  if Configuration::XcodeSettings.all_valid?
15
- say "Done"
18
+ task.success "Done."
16
19
  else
20
+ task.error "Failed."
17
21
  say "Failed to load settings from Xcode. Some information may be missing.\n"
18
22
  end
19
23
 
@@ -50,13 +54,13 @@ module BranchIOCLI
50
54
  tool_helper.carthage_bootstrap_if_required report
51
55
 
52
56
  # run xcodebuild -list
53
- report.sh(*report_helper.base_xcodebuild_cmd, "-list")
57
+ report.sh(*report_helper.base_xcodebuild_cmd, "-list", obfuscate: true)
54
58
 
55
59
  # If using a workspace, -list all the projects as well
56
60
  if config.workspace_path
57
61
  config.workspace.file_references.map(&:path).each do |project_path|
58
62
  path = File.join File.dirname(config.workspace_path), project_path
59
- report.sh "xcodebuild", "-list", "-project", path
63
+ report.sh "xcodebuild", "-list", "-project", path, obfuscate: true
60
64
  end
61
65
  end
62
66
 
@@ -77,19 +81,21 @@ module BranchIOCLI
77
81
  ]
78
82
 
79
83
  if config.clean
80
- say "Cleaning"
81
- if report.sh(*base_cmd, "clean").success?
82
- say "Done ✅"
84
+ task = Helper::Task.new use_spinner: report != STDOUT
85
+ task.begin "Cleaning."
86
+ if report.sh(*base_cmd, "clean", obfuscate: true).success?
87
+ task.success "Done."
83
88
  else
84
- say "Clean failed."
89
+ task.error "Clean failed."
85
90
  end
86
91
  end
87
92
 
88
- say "Building"
89
- if report.sh(*base_cmd, "-verbose").success?
90
- say "Done ✅"
93
+ task = Helper::Task.new use_spinner: report != STDOUT
94
+ task.begin "Building."
95
+ if report.sh(*base_cmd, "-verbose", obfuscate: true).success?
96
+ task.success "Done."
91
97
  else
92
- say "Build failed."
98
+ task.error "Failed."
93
99
  end
94
100
  end
95
101
 
@@ -130,6 +130,10 @@ EOF
130
130
  target.name.nil? ? nil : target.name
131
131
  end
132
132
 
133
+ def env
134
+ Environment
135
+ end
136
+
133
137
  def root
134
138
  return @root if @root
135
139
  if workspace
@@ -327,8 +331,7 @@ EOF
327
331
  end
328
332
 
329
333
  def pod_install_required?
330
- # If this is set, its existence has been verified.
331
- return false unless podfile_path
334
+ return false unless podfile_path && File.exist?(podfile_path)
332
335
 
333
336
  lockfile_path = "#{podfile_path}.lock"
334
337
  manifest_path = File.expand_path "../Pods/Manifest.lock", podfile_path
@@ -88,15 +88,17 @@ module BranchIOCLI
88
88
  if terminal
89
89
  "<%= color('#{label}:', BOLD) %> #{value}\n"
90
90
  else
91
- "label: #{value}\n"
91
+ "#{label}: #{value}\n"
92
92
  end
93
93
  end
94
94
 
95
95
  def obfuscate_user(path)
96
+ return nil if path.nil?
96
97
  path.gsub(ENV['HOME'], '~').gsub(ENV['USER'], '$USER')
97
98
  end
98
99
 
99
100
  def display_path(path)
101
+ return nil if path.nil?
100
102
  path = path.gsub(Gem.dir, '$GEM_HOME')
101
103
  path = obfuscate_user(path)
102
104
  path
@@ -50,8 +50,8 @@ module BranchIOCLI
50
50
  <<EOF
51
51
  Configuration:
52
52
 
53
- Xcode workspace: #{workspace_path || '(none)'}
54
- Xcode project: #{xcodeproj_path || '(none)'}
53
+ Xcode workspace: #{env.display_path(workspace_path) || '(none)'}
54
+ Xcode project: #{env.display_path(xcodeproj_path) || '(none)'}
55
55
  Scheme: #{scheme || '(none)'}
56
56
  Target: #{target || '(none)'}
57
57
  Configuration: #{configuration || '(none)'}
@@ -66,8 +66,8 @@ EOF
66
66
  def log
67
67
  super
68
68
  say <<EOF
69
- <%= color('Xcode workspace:', BOLD) %> #{workspace_path || '(none)'}
70
- <%= color('Xcode project:', BOLD) %> #{xcodeproj_path || '(none)'}
69
+ <%= color('Xcode workspace:', BOLD) %> #{env.display_path(workspace_path) || '(none)'}
70
+ <%= color('Xcode project:', BOLD) %> #{env.display_path(xcodeproj_path) || '(none)'}
71
71
  <%= color('Scheme:', BOLD) %> #{scheme || '(none)'}
72
72
  <%= color('Target:', BOLD) %> #{target || '(none)'}
73
73
  <%= color('Target type:', BOLD) %> #{target.product_type}
@@ -73,7 +73,7 @@ module BranchIOCLI
73
73
  def log
74
74
  super
75
75
  message = <<-EOF
76
- <%= color('Xcode project:', BOLD) %> #{xcodeproj_path}
76
+ <%= color('Xcode project:', BOLD) %> #{env.display_path(xcodeproj_path)}
77
77
  <%= color('Target:', BOLD) %> #{target.name}
78
78
  <%= color('Target type:', BOLD) %> #{target.product_type}
79
79
  <%= color('Live key:', BOLD) %> #{keys[:live] || '(none)'}
@@ -34,7 +34,7 @@ module BranchIOCLI
34
34
  def log
35
35
  super
36
36
  say <<EOF
37
- <%= color('Xcode project:', BOLD) %> #{xcodeproj_path}
37
+ <%= color('Xcode project:', BOLD) %> #{env.display_path(xcodeproj_path)}
38
38
  <%= color('Target:', BOLD) %> #{target.name}
39
39
  <%= color('Target type:', BOLD) %> #{target.product_type}
40
40
  <%= color('Live key:', BOLD) %> #{keys[:live] || '(none)'}
@@ -1,5 +1,6 @@
1
1
  require "open3"
2
2
  require "shellwords"
3
+ require_relative "environment"
3
4
 
4
5
  module BranchIOCLI
5
6
  module Configuration
@@ -41,6 +42,10 @@ module BranchIOCLI
41
42
  Configuration.current
42
43
  end
43
44
 
45
+ def env
46
+ Environment
47
+ end
48
+
44
49
  def [](key)
45
50
  @xcode_settings[key]
46
51
  end
@@ -65,7 +70,7 @@ module BranchIOCLI
65
70
  @xcode_settings = {}
66
71
  Open3.popen2e(xcodebuild_cmd) do |stdin, output, thread|
67
72
  while (line = output.gets)
68
- @xcodebuild_showbuildsettings_output += line
73
+ @xcodebuild_showbuildsettings_output += env.obfuscate_user(line)
69
74
  line.strip!
70
75
  next unless (matches = /^(.+)\s+=\s+(.+)$/.match line)
71
76
  @xcode_settings[matches[1]] = matches[2]
@@ -78,7 +83,7 @@ module BranchIOCLI
78
83
  if report == STDOUT
79
84
  say "<%= color('$ #{xcodebuild_cmd}', [MAGENTA, BOLD]) %>\n\n"
80
85
  else
81
- report.write "$ #{xcodebuild_cmd}\n\n"
86
+ report.write "$ #{env.obfuscate_user(xcodebuild_cmd)}\n\n"
82
87
  end
83
88
 
84
89
  report.write @xcodebuild_showbuildsettings_output
@@ -1,5 +1,6 @@
1
1
  require "open3"
2
2
  require "shellwords"
3
+ require_relative "../configuration/environment"
3
4
 
4
5
  class IO
5
6
  # Report the command. Execute the command, capture stdout
@@ -11,10 +12,16 @@ class IO
11
12
  def sh(*args)
12
13
  write "$ #{IO.command_from_args(*args)}\n\n"
13
14
 
15
+ obfuscate = args.last.delete(:obfuscate) if args.last.kind_of?(Hash)
16
+
14
17
  Open3.popen2e(*args) do |stdin, output, thread|
15
18
  # output is stdout and stderr merged
16
- while (line = output.gets)
17
- puts line
19
+ output.each do |line|
20
+ if obfuscate
21
+ puts BranchIOCLI::Configuration::Environment.obfuscate_user(line)
22
+ else
23
+ puts line
24
+ end
18
25
  end
19
26
 
20
27
  status = thread.value
@@ -34,9 +41,12 @@ end
34
41
  #
35
42
  # @param command a shell command to execute and report
36
43
  def STDOUT.sh(*args)
44
+ args.last.delete(:obfuscate) if args.last.kind_of?(Hash)
45
+
37
46
  # TODO: Improve this implementation?
38
47
  say "<%= color(%q{$ #{IO.command_from_args(*args)}}, [MAGENTA, BOLD]) %>\n\n"
39
48
  # May also write to stderr
49
+ # Cannot obfuscate here.
40
50
  system(*args)
41
51
 
42
52
  status = $?
@@ -52,7 +62,10 @@ def IO.command_from_args(*args)
52
62
  raise ArgumentError, "sh requires at least one argument" unless args.count > 0
53
63
 
54
64
  # Ignore any trailing options in the output
55
- args.pop if args.last.kind_of?(Hash)
65
+ if args.last.kind_of?(Hash)
66
+ options = args.pop
67
+ obfuscate = options[:obfuscate]
68
+ end
56
69
 
57
70
  command = ""
58
71
 
@@ -71,5 +84,9 @@ def IO.command_from_args(*args)
71
84
  command += args.shelljoin
72
85
  end
73
86
 
74
- command
87
+ if obfuscate
88
+ BranchIOCLI::Configuration::Environment.obfuscate_user(command)
89
+ else
90
+ command
91
+ end
75
92
  end
@@ -2,5 +2,6 @@ require_relative "helper/branch_helper"
2
2
  require_relative "helper/methods"
3
3
  require_relative "helper/patch_helper"
4
4
  require_relative "helper/report_helper"
5
+ require_relative "helper/task"
5
6
  require_relative "helper/tool_helper"
6
7
  require_relative "helper/util"
@@ -1,5 +1,5 @@
1
1
  require "active_support/core_ext/object"
2
- require "json"
2
+ require "active_support/json"
3
3
  require "openssl"
4
4
  require "plist"
5
5
  require "tty/spinner"
@@ -0,0 +1,34 @@
1
+ require "tty/spinner"
2
+
3
+ module BranchIOCLI
4
+ module Helper
5
+ class Task
6
+ def initialize(use_spinner: true)
7
+ @use_spinner = use_spinner
8
+ end
9
+
10
+ def use_spinner?
11
+ @use_spinner
12
+ end
13
+
14
+ def begin(message)
15
+ if use_spinner?
16
+ @spinner = TTY::Spinner.new "[:spinner] #{message}", format: :flip
17
+ @spinner.auto_spin
18
+ end
19
+ end
20
+
21
+ def success(message)
22
+ if use_spinner?
23
+ @spinner.success message
24
+ end
25
+ end
26
+
27
+ def error(message)
28
+ if use_spinner?
29
+ @spinner.error message
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -31,7 +31,7 @@ module BranchIOCLI
31
31
  install_command = %w(pod install)
32
32
  install_command << "--repo-update" if options.pod_repo_update
33
33
  Dir.chdir(File.dirname(podfile_path)) do
34
- sh %w(pod init)
34
+ sh "pod", "init"
35
35
  PatternPatch::Patch.new(
36
36
  regexp: /^(\s*)# Pods for #{options.target.name}$/,
37
37
  mode: :append,
@@ -77,7 +77,7 @@ github "BranchMetrics/ios-branch-deep-linking"
77
77
  end
78
78
 
79
79
  # 2. carthage update
80
- sh "carthage", options.carthage_command, chdir: File.dirname(config.cartfile_path)
80
+ sh "carthage", *options.carthage_command.shellsplit, chdir: File.dirname(config.cartfile_path)
81
81
 
82
82
  # 3. Add Cartfile and Cartfile.resolved to commit (in case :commit param specified)
83
83
  helper.add_change cartfile_path
@@ -193,7 +193,6 @@ github "BranchMetrics/ios-branch-deep-linking"
193
193
  return false unless PatchHelper.patch_podfile podfile_path
194
194
 
195
195
  # 2. pod install
196
- # command = "PATH='#{ENV['PATH']}' pod install"
197
196
  command = %w(pod install)
198
197
  command << '--repo-update' if options.pod_repo_update
199
198
 
@@ -306,7 +305,7 @@ github "BranchMetrics/ios-branch-deep-linking"
306
305
 
307
306
  # Ensure master podspec repo is set up (will update if it exists).
308
307
  say "Synching master podspec repo. This may take some time."
309
- sh %w(pod setup)
308
+ sh "pod", "setup"
310
309
  say "Done ✅"
311
310
  end
312
311
 
@@ -326,7 +325,7 @@ github "BranchMetrics/ios-branch-deep-linking"
326
325
  exit(-1)
327
326
  end
328
327
 
329
- sh %w(brew install carthage)
328
+ sh "brew", "install", "carthage"
330
329
  end
331
330
 
332
331
  def verify_git
@@ -347,7 +346,7 @@ github "BranchMetrics/ios-branch-deep-linking"
347
346
  exit(-1)
348
347
  end
349
348
 
350
- sh %w(xcode-select --install)
349
+ sh "xcode-select", "--install"
351
350
  end
352
351
 
353
352
  def pod_install_if_required(report = STDOUT)
@@ -378,11 +377,13 @@ some cases. If that happens, please rerun without --no-pod-repo-update or run
378
377
  EOF
379
378
  end
380
379
 
380
+ task = Task.new use_spinner: report != STDOUT
381
381
  # included by sh, but this is to the screen when generating a report.
382
- say "Running #{IO.command_from_args(*install_command)}"
382
+ task.begin "Running #{IO.command_from_args(*install_command)}."
383
383
  if report.sh(*install_command).success?
384
- say "Done"
384
+ task.success "Done."
385
385
  else
386
+ task.error "Failed."
386
387
  say "#{IO.command_from_args(*install_command)} failed. See report for details."
387
388
  return false
388
389
  end
@@ -408,22 +409,26 @@ some cases. If that happens, please rerun without --no-pod-repo-update or run
408
409
 
409
410
  checkout_command = %w(carthage checkout)
410
411
 
412
+ task = Task.new use_spinner: report != STDOUT
411
413
  # included by sh, but this is to the screen when generating a report.
412
- say "Running #{IO.command_from_args(*checkout_command)}"
414
+ task.begin "Running #{IO.command_from_args(*checkout_command)}."
413
415
  if report.sh(*checkout_command).success?
414
- say "Done"
416
+ task.success "Done."
415
417
  else
418
+ task.error "Failed."
416
419
  say "#{IO.command_from_args(*checkout_command)} failed. See report for details."
417
420
  return false
418
421
  end
419
422
 
420
- build_command = %w(carthage build --platform ios)
423
+ build_command = "carthage", "build", "--platform", "ios"
421
424
 
425
+ task = Task.new use_spinner: report != STDOUT
422
426
  # included by sh, but this is to the screen when generating a report.
423
- say "Running #{IO.command_from_args(*build_command)}"
427
+ task.begin "Running #{IO.command_from_args(*build_command)}."
424
428
  if report.sh(*build_command).success?
425
- say "Done"
429
+ task.success "Done."
426
430
  else
431
+ task.error "Failed."
427
432
  say "#{IO.command_from_args(*build_command)} failed. See report for details."
428
433
  return false
429
434
  end
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.1"
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.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branch
@@ -414,6 +414,7 @@ files:
414
414
  - lib/branch_io_cli/helper/methods.rb
415
415
  - lib/branch_io_cli/helper/patch_helper.rb
416
416
  - lib/branch_io_cli/helper/report_helper.rb
417
+ - lib/branch_io_cli/helper/task.rb
417
418
  - lib/branch_io_cli/helper/tool_helper.rb
418
419
  - lib/branch_io_cli/helper/util.rb
419
420
  - lib/branch_io_cli/rake_task.rb