branch_io_cli 0.11.0 → 0.12.0
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 +4 -4
- data/README.md +58 -50
- data/lib/assets/completions/completion.bash +1 -1
- data/lib/assets/completions/completion.zsh +1 -1
- data/lib/assets/templates/command.erb +5 -5
- data/lib/branch_io_cli/cli.rb +56 -45
- data/lib/branch_io_cli/command/report_command.rb +3 -1
- data/lib/branch_io_cli/command/setup_command.rb +19 -15
- data/lib/branch_io_cli/command/validate_command.rb +3 -3
- data/lib/branch_io_cli/configuration/configuration.rb +159 -22
- data/lib/branch_io_cli/configuration/option.rb +78 -0
- data/lib/branch_io_cli/configuration/option_wrapper.rb +5 -2
- data/lib/branch_io_cli/configuration/report_configuration.rb +7 -42
- data/lib/branch_io_cli/configuration/setup_configuration.rb +43 -15
- data/lib/branch_io_cli/configuration/validate_configuration.rb +4 -0
- data/lib/branch_io_cli/format.rb +1 -1
- data/lib/branch_io_cli/format/{commander_format.rb → highline_format.rb} +1 -1
- data/lib/branch_io_cli/format/markdown_format.rb +4 -0
- data/lib/branch_io_cli/helper.rb +3 -0
- data/lib/branch_io_cli/helper/ios_helper.rb +36 -99
- data/lib/branch_io_cli/helper/methods.rb +18 -2
- data/lib/branch_io_cli/helper/report_helper.rb +11 -8
- data/lib/branch_io_cli/helper/util.rb +7 -0
- data/lib/branch_io_cli/helper/xcodeproj_ext.rb +126 -0
- data/lib/branch_io_cli/rake_task.rb +2 -2
- data/lib/branch_io_cli/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be0daf95d93295d62f31315a658b57fc4907530d6f4a1b6dc1fef5366a18d78e
|
|
4
|
+
data.tar.gz: 63c2469083e71c37a99ebcaeabc67eb11e76efa2ad2ddf7210c66b2daad1aced
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bda3669c526febfb881867e4f583340ee8d3450d2683d7d3631fca1b8719e44ed73b5d2ff9b93ca415243e92c4675e76014e5938b029bf5c2e3276b3a09ed47f
|
|
7
|
+
data.tar.gz: be88db9e6b26f92a18a9aac27d6004f82fdc9e63cc6cb06c039a1edc97cce206788531c650b9aff4fbb40f94cbd1238551e47c263b2b015b1fadbb8dde7b8121
|
data/README.md
CHANGED
|
@@ -124,31 +124,31 @@ See https://github.com/BranchMetrics/branch_io_cli#setup-command for more inform
|
|
|
124
124
|
|
|
125
125
|
#### Options
|
|
126
126
|
|
|
127
|
-
|Option|Description|
|
|
128
|
-
|
|
129
|
-
|-h, --help|Prints a list of commands or help for each command
|
|
130
|
-
|-v, --version|Prints the current version of the CLI
|
|
131
|
-
|-t, --trace|Prints a stack trace when exceptions are raised
|
|
132
|
-
|-L, --live-key key_live_xxxx|Branch live key|
|
|
133
|
-
|-T, --test-key key_test_yyyy|Branch test key|
|
|
134
|
-
|-D, --domains example.com,www.example.com|Comma-separated list of custom domain(s) or non-Branch domain(s)|
|
|
135
|
-
|--app-link-subdomain myapp|Branch app.link subdomain, e.g. myapp for myapp.app.link|
|
|
136
|
-
|-U, --uri-scheme myurischeme[://]|Custom URI scheme used in the Branch Dashboard for this app|
|
|
137
|
-
|-s, --setting [BRANCH_KEY_SETTING]|Use a custom build setting for the Branch key (default: Use Info.plist)|
|
|
138
|
-
|--test-configurations config1,config2|List of configurations that use the test key with a
|
|
139
|
-
|--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
|
|
140
|
-
|--target MyAppTarget|Name of a target to modify in the Xcode project|
|
|
141
|
-
|--podfile /path/to/Podfile|Path to the Podfile for the project|
|
|
142
|
-
|--cartfile /path/to/Cartfile|Path to the Cartfile for the project|
|
|
143
|
-
|--carthage-command <command>|Command to run when installing from Carthage (default: update --platform ios)|
|
|
144
|
-
|--frameworks AdSupport,CoreSpotlight,SafariServices|Comma-separated list of system frameworks to add to the project|
|
|
145
|
-
|--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|
|
|
146
|
-
|--[no-]validate|Validate Universal Link configuration (default: yes)|
|
|
147
|
-
|--[no-]force|Update project even if Universal Link validation fails (default: no)|
|
|
148
|
-
|--[no-]add-sdk|Add the Branch framework to the project (default: yes)|
|
|
149
|
-
|--[no-]patch-source|Add Branch SDK calls to the AppDelegate (default: yes)|
|
|
150
|
-
|--commit [message]|Commit the results to Git|
|
|
151
|
-
|--[no-]
|
|
127
|
+
|Option|Description|Env. var.|
|
|
128
|
+
|------|-----------|---------|
|
|
129
|
+
|-h, --help|Prints a list of commands or help for each command||
|
|
130
|
+
|-v, --version|Prints the current version of the CLI||
|
|
131
|
+
|-t, --trace|Prints a stack trace when exceptions are raised||
|
|
132
|
+
|-L, --live-key key_live_xxxx|Branch live key|BRANCH_LIVE_KEY|
|
|
133
|
+
|-T, --test-key key_test_yyyy|Branch test key|BRANCH_TEST_KEY|
|
|
134
|
+
|-D, --domains example.com,www.example.com|Comma-separated list of custom domain(s) or non-Branch domain(s)|BRANCH_DOMAINS|
|
|
135
|
+
|--app-link-subdomain myapp|Branch app.link subdomain, e.g. myapp for myapp.app.link|BRANCH_APP_LINK_SUBDOMAIN|
|
|
136
|
+
|-U, --uri-scheme myurischeme[://]|Custom URI scheme used in the Branch Dashboard for this app|BRANCH_URI_SCHEME|
|
|
137
|
+
|-s, --setting [BRANCH_KEY_SETTING]|Use a custom build setting for the Branch key (default: Use Info.plist)|BRANCH_SETTING|
|
|
138
|
+
|--[no-]test-configurations [config1,config2]|List of configurations that use the test key with a user-defined setting (default: Debug configurations)|BRANCH_TEST_CONFIGURATIONS|
|
|
139
|
+
|--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|BRANCH_XCODEPROJ|
|
|
140
|
+
|--target MyAppTarget|Name of a target to modify in the Xcode project|BRANCH_TARGET|
|
|
141
|
+
|--podfile /path/to/Podfile|Path to the Podfile for the project|BRANCH_PODFILE|
|
|
142
|
+
|--cartfile /path/to/Cartfile|Path to the Cartfile for the project|BRANCH_CARTFILE|
|
|
143
|
+
|--carthage-command <command>|Command to run when installing from Carthage (default: update --platform ios)|BRANCH_CARTHAGE_COMMAND|
|
|
144
|
+
|--frameworks AdSupport,CoreSpotlight,SafariServices|Comma-separated list of system frameworks to add to the project|BRANCH_FRAMEWORKS|
|
|
145
|
+
|--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|BRANCH_POD_REPO_UPDATE|
|
|
146
|
+
|--[no-]validate|Validate Universal Link configuration (default: yes)|BRANCH_VALIDATE|
|
|
147
|
+
|--[no-]force|Update project even if Universal Link validation fails (default: no)|BRANCH_FORCE|
|
|
148
|
+
|--[no-]add-sdk|Add the Branch framework to the project (default: yes)|BRANCH_ADD_SDK|
|
|
149
|
+
|--[no-]patch-source|Add Branch SDK calls to the AppDelegate (default: yes)|BRANCH_PATCH_SOURCE|
|
|
150
|
+
|--commit [message]|Commit the results to Git if non-blank|BRANCH_COMMIT|
|
|
151
|
+
|--[no-]confirm|Confirm configuration before proceeding (default: yes)|BRANCH_CONFIRM|
|
|
152
152
|
|
|
153
153
|
|
|
154
154
|
#### Examples
|
|
@@ -219,14 +219,14 @@ See https://github.com/BranchMetrics/branch_io_cli#validate-command for more inf
|
|
|
219
219
|
|
|
220
220
|
#### Options
|
|
221
221
|
|
|
222
|
-
|Option|Description|
|
|
223
|
-
|
|
224
|
-
|-h, --help|Prints a list of commands or help for each command
|
|
225
|
-
|-v, --version|Prints the current version of the CLI
|
|
226
|
-
|-t, --trace|Prints a stack trace when exceptions are raised
|
|
227
|
-
|-D, --domains example.com,www.example.com|Comma-separated list of domains to validate (Branch domains or non-Branch domains) (default: [])|
|
|
228
|
-
|--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
|
|
229
|
-
|--target MyAppTarget|Name of a target to validate in the Xcode project|
|
|
222
|
+
|Option|Description|Env. var.|
|
|
223
|
+
|------|-----------|---------|
|
|
224
|
+
|-h, --help|Prints a list of commands or help for each command||
|
|
225
|
+
|-v, --version|Prints the current version of the CLI||
|
|
226
|
+
|-t, --trace|Prints a stack trace when exceptions are raised||
|
|
227
|
+
|-D, --domains example.com,www.example.com|Comma-separated list of domains to validate (Branch domains or non-Branch domains) (default: [])|BRANCH_DOMAINS|
|
|
228
|
+
|--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|BRANCH_XCODEPROJ|
|
|
229
|
+
|--target MyAppTarget|Name of a target to validate in the Xcode project|BRANCH_TARGET|
|
|
230
230
|
|
|
231
231
|
|
|
232
232
|
|
|
@@ -246,23 +246,23 @@ report with additional diagnostic information suitable for opening a support tic
|
|
|
246
246
|
|
|
247
247
|
#### Options
|
|
248
248
|
|
|
249
|
-
|Option|Description|
|
|
250
|
-
|
|
251
|
-
|-h, --help|Prints a list of commands or help for each command
|
|
252
|
-
|-v, --version|Prints the current version of the CLI
|
|
253
|
-
|-t, --trace|Prints a stack trace when exceptions are raised
|
|
254
|
-
|--workspace MyProject.xcworkspace|Path to an Xcode workspace|
|
|
255
|
-
|--xcodeproj MyProject.xcodeproj|Path to an Xcode project|
|
|
256
|
-
|--scheme MyProjectScheme|A scheme from the project or workspace to build|
|
|
257
|
-
|--target MyProjectTarget|A target to build|
|
|
258
|
-
|--configuration Debug/Release/CustomConfigName|The build configuration to use (default: Scheme-dependent)|
|
|
259
|
-
|--sdk iphoneos|Passed as -sdk to xcodebuild (default: iphonesimulator)|
|
|
260
|
-
|--podfile /path/to/Podfile|Path to the Podfile for the project|
|
|
261
|
-
|--cartfile /path/to/Cartfile|Path to the Cartfile for the project|
|
|
262
|
-
|--[no-]clean|Clean before attempting to build (default: yes)|
|
|
263
|
-
|-H, --[no-]header-only|Write a report header to standard output and exit (default: no)|
|
|
264
|
-
|--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|
|
|
265
|
-
|-o, --out ./report.txt|Report output path (default: ./report.txt)|
|
|
249
|
+
|Option|Description|Env. var.|
|
|
250
|
+
|------|-----------|---------|
|
|
251
|
+
|-h, --help|Prints a list of commands or help for each command||
|
|
252
|
+
|-v, --version|Prints the current version of the CLI||
|
|
253
|
+
|-t, --trace|Prints a stack trace when exceptions are raised||
|
|
254
|
+
|--workspace MyProject.xcworkspace|Path to an Xcode workspace|BRANCH_WORKSPACE|
|
|
255
|
+
|--xcodeproj MyProject.xcodeproj|Path to an Xcode project|BRANCH_XCODEPROJ|
|
|
256
|
+
|--scheme MyProjectScheme|A scheme from the project or workspace to build|BRANCH_SCHEME|
|
|
257
|
+
|--target MyProjectTarget|A target to build|BRANCH_TARGET|
|
|
258
|
+
|--configuration Debug/Release/CustomConfigName|The build configuration to use (default: Scheme-dependent)|BRANCH_CONFIGURATION|
|
|
259
|
+
|--sdk iphoneos|Passed as -sdk to xcodebuild (default: iphonesimulator)|BRANCH_SDK|
|
|
260
|
+
|--podfile /path/to/Podfile|Path to the Podfile for the project|BRANCH_PODFILE|
|
|
261
|
+
|--cartfile /path/to/Cartfile|Path to the Cartfile for the project|BRANCH_CARTFILE|
|
|
262
|
+
|--[no-]clean|Clean before attempting to build (default: yes)|BRANCH_CLEAN|
|
|
263
|
+
|-H, --[no-]header-only|Write a report header to standard output and exit (default: no)|BRANCH_HEADER_ONLY|
|
|
264
|
+
|--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|BRANCH_POD_REPO_UPDATE|
|
|
265
|
+
|-o, --out ./report.txt|Report output path (default: ./report.txt)|BRANCH_REPORT_PATH|
|
|
266
266
|
|
|
267
267
|
|
|
268
268
|
|
|
@@ -292,3 +292,11 @@ arguments. For example:
|
|
|
292
292
|
```Ruby
|
|
293
293
|
Rake::Task["branch:validate"].invoke ".", domains: %w(example.com www.example.com)
|
|
294
294
|
```
|
|
295
|
+
|
|
296
|
+
Try the following Rake tasks in this repo:
|
|
297
|
+
|
|
298
|
+
```Ruby
|
|
299
|
+
bundle exec rake setup
|
|
300
|
+
bundle exec rake validate
|
|
301
|
+
bundle exec rake report
|
|
302
|
+
```
|
|
@@ -13,7 +13,7 @@ _branch_io_complete()
|
|
|
13
13
|
|
|
14
14
|
setup_opts="$global_opts -L --live-key -T --test-key -D --domains --app-link-subdomain -U --uri-scheme"
|
|
15
15
|
setup_opts="$setup_opts --xcodeproj --target --frameworks --podfile --cartfile --carthage-command --setting -s"
|
|
16
|
-
setup_opts="$setup_opts --test-configurations --no-test-configurations --no-check-repo-changes"
|
|
16
|
+
setup_opts="$setup_opts --test-configurations --no-test-configurations --no-check-repo-changes --no-confirm"
|
|
17
17
|
# Don't autocomplete the default values here, e.g. --no-force, --pod-repo-update.
|
|
18
18
|
setup_opts="$setup_opts --no-add-sdk --no-validate --force --no-pod-repo-update --commit --no-patch-source"
|
|
19
19
|
|
|
@@ -6,7 +6,7 @@ _branch_io_complete() {
|
|
|
6
6
|
opts="-h --help -t --trace -v --version"
|
|
7
7
|
opts="$opts -L --live-key -T --test-key -D --domains --app-link-subdomain -U --uri-scheme"
|
|
8
8
|
opts="$opts --xcodeproj --target --frameworks --podfile --cartfile --carthage-command --setting -s"
|
|
9
|
-
opts="$opts --test-configurations --no-test-configurations --no-check-repo-changes"
|
|
9
|
+
opts="$opts --test-configurations --no-test-configurations --no-check-repo-changes --no-confirm"
|
|
10
10
|
# Don't autocomplete the default values here, e.g. --no-force, --pod-repo-update.
|
|
11
11
|
opts="$opts --no-add-sdk --no-validate --force --no-pod-repo-update --commit --no-patch-source"
|
|
12
12
|
|
|
@@ -8,11 +8,11 @@ branch_io <%= @command.command_name %> [OPTIONS]
|
|
|
8
8
|
|
|
9
9
|
<%= header "Options", 4 %>
|
|
10
10
|
|
|
11
|
-
|Option|Description|
|
|
12
|
-
|
|
13
|
-
|-h, --help|Prints a list of commands or help for each command
|
|
14
|
-
|-v, --version|Prints the current version of the CLI
|
|
15
|
-
|-t, --trace|Prints a stack trace when exceptions are raised
|
|
11
|
+
|Option|Description|Env. var.|
|
|
12
|
+
|------|-----------|---------|
|
|
13
|
+
|-h, --help|Prints a list of commands or help for each command||
|
|
14
|
+
|-v, --version|Prints the current version of the CLI||
|
|
15
|
+
|-t, --trace|Prints a stack trace when exceptions are raised||
|
|
16
16
|
<%= table_options %>
|
|
17
17
|
|
|
18
18
|
<% if @command.respond_to?(:examples) && !@command.examples.blank? %>
|
data/lib/branch_io_cli/cli.rb
CHANGED
|
@@ -5,73 +5,83 @@ require "branch_io_cli/format"
|
|
|
5
5
|
module BranchIOCLI
|
|
6
6
|
class CLI
|
|
7
7
|
include Commander::Methods
|
|
8
|
-
include Format::
|
|
8
|
+
include Format::HighlineFormat
|
|
9
9
|
|
|
10
10
|
def run
|
|
11
11
|
program :name, "Branch.io command-line interface"
|
|
12
12
|
program :version, VERSION
|
|
13
13
|
program :description, render(:program_description)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
c.description = render :setup_description
|
|
19
|
-
|
|
20
|
-
add_options_for_command :setup, c
|
|
21
|
-
|
|
22
|
-
Command::SetupCommand.examples.each_key do |text|
|
|
23
|
-
example = Command::SetupCommand.examples[text]
|
|
24
|
-
c.example text, example
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
c.action do |args, options|
|
|
28
|
-
options.default Configuration::SetupConfiguration.defaults
|
|
29
|
-
Command::SetupCommand.new(options).run!
|
|
30
|
-
end
|
|
15
|
+
# Automatically detect all commands from branch_io_cli/command.
|
|
16
|
+
all_commands = Dir[File.expand_path(File.join("..", "command", "*_command.rb"), __FILE__)].map do |path|
|
|
17
|
+
File.basename(path, ".rb").sub(/_command$/, "")
|
|
31
18
|
end
|
|
32
19
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
all_commands.each do |command_name|
|
|
21
|
+
configuration_class = configuration_class command_name
|
|
22
|
+
command_class = command_class command_name
|
|
23
|
+
next unless configuration_class && command_class
|
|
24
|
+
|
|
25
|
+
command command_name do |c|
|
|
26
|
+
c.syntax = "branch_io #{c.name} [OPTIONS]"
|
|
27
|
+
c.summary = configuration_class.summary if configuration_class.respond_to?(:summary)
|
|
28
|
+
|
|
29
|
+
begin
|
|
30
|
+
c.description = render "#{c.name}_description"
|
|
31
|
+
rescue Errno::ENOENT
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
add_options_for_command c
|
|
35
|
+
|
|
36
|
+
if configuration_class.respond_to?(:examples) && configuration_class.examples
|
|
37
|
+
configuration_class.examples.each_key do |text|
|
|
38
|
+
example = configuration_class.examples[text]
|
|
39
|
+
c.example text, example
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
c.action do |args, options|
|
|
44
|
+
options.default configuration_class.defaults
|
|
45
|
+
return_value = command_class.new(options).run!
|
|
46
|
+
exit(return_value.respond_to?(:to_i) ? return_value.to_i : 0)
|
|
47
|
+
end
|
|
45
48
|
end
|
|
46
49
|
end
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
c.summary = "Generate and optionally submit a build diagnostic report."
|
|
51
|
-
c.description = render :report_description
|
|
51
|
+
run!
|
|
52
|
+
end
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
def configuration_class(name)
|
|
55
|
+
class_for_command name, :configuration
|
|
56
|
+
end
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
58
|
+
def command_class(name)
|
|
59
|
+
class_for_command name, :command
|
|
60
|
+
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
def class_for_command(name, type)
|
|
63
|
+
type_name = type.to_s.capitalize
|
|
64
|
+
type_module = Object.const_get("BranchIOCLI").const_get(type_name)
|
|
65
|
+
candidate = type_module.const_get("#{name.to_s.capitalize}#{type_name}")
|
|
66
|
+
return nil unless candidate
|
|
67
|
+
|
|
68
|
+
base = type_module.const_get(type_name)
|
|
69
|
+
return nil unless candidate.superclass == base
|
|
70
|
+
candidate
|
|
62
71
|
end
|
|
63
72
|
|
|
64
|
-
def add_options_for_command(
|
|
65
|
-
configuration_class =
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
def add_options_for_command(c)
|
|
74
|
+
configuration_class = configuration_class(c.name)
|
|
75
|
+
return unless configuration_class.respond_to?(:available_options)
|
|
76
|
+
|
|
68
77
|
available_options = configuration_class.available_options
|
|
69
78
|
available_options.each do |option|
|
|
70
79
|
args = option.aliases
|
|
71
80
|
declaration = "--"
|
|
72
81
|
declaration += "[no-]" if option.negatable
|
|
73
|
-
declaration +=
|
|
82
|
+
declaration += option.name.to_s.gsub(/_/, '-')
|
|
74
83
|
if option.example
|
|
84
|
+
declaration += " "
|
|
75
85
|
declaration += "[" if option.argument_optional
|
|
76
86
|
declaration += option.example
|
|
77
87
|
declaration += "]" if option.argument_optional
|
|
@@ -87,6 +97,7 @@ module BranchIOCLI
|
|
|
87
97
|
|
|
88
98
|
default_string = default_value ? " (default: #{default_value})" : nil
|
|
89
99
|
args << "#{option.description}#{default_string}"
|
|
100
|
+
|
|
90
101
|
c.option(*args)
|
|
91
102
|
end
|
|
92
103
|
end
|
|
@@ -19,7 +19,7 @@ module BranchIOCLI
|
|
|
19
19
|
|
|
20
20
|
if config.header_only
|
|
21
21
|
say report_helper.report_header
|
|
22
|
-
return
|
|
22
|
+
return 0
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
if config.report_path == "stdout"
|
|
@@ -28,6 +28,8 @@ module BranchIOCLI
|
|
|
28
28
|
File.open(config.report_path, "w") { |f| write_report f }
|
|
29
29
|
say "Report generated in #{config.report_path}"
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
0
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def write_report(report)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
require "branch_io_cli/helper
|
|
1
|
+
require "branch_io_cli/helper"
|
|
2
2
|
|
|
3
3
|
module BranchIOCLI
|
|
4
4
|
module Command
|
|
5
5
|
class SetupCommand < Command
|
|
6
|
+
include Helper::Methods
|
|
7
|
+
|
|
6
8
|
def initialize(options)
|
|
7
9
|
super
|
|
8
10
|
@keys = config.keys
|
|
@@ -18,12 +20,12 @@ module BranchIOCLI
|
|
|
18
20
|
|
|
19
21
|
is_app_target = !config.target.extension_target_type?
|
|
20
22
|
|
|
21
|
-
if is_app_target &&
|
|
23
|
+
if is_app_target && config.validate &&
|
|
22
24
|
!helper.validate_team_and_bundle_ids_from_aasa_files(@domains)
|
|
23
25
|
say "Universal Link configuration failed validation."
|
|
24
26
|
helper.errors.each { |error| say " #{error}" }
|
|
25
|
-
return unless
|
|
26
|
-
elsif is_app_target &&
|
|
27
|
+
return 1 unless config.force
|
|
28
|
+
elsif is_app_target && config.validate
|
|
27
29
|
say "Universal Link configuration passed validation. ✅"
|
|
28
30
|
end
|
|
29
31
|
|
|
@@ -44,39 +46,41 @@ module BranchIOCLI
|
|
|
44
46
|
helper.ensure_uri_scheme_in_info_plist if is_app_target # does nothing if already present
|
|
45
47
|
|
|
46
48
|
new_path = helper.add_universal_links_to_project @domains, false if is_app_target
|
|
47
|
-
sh ["git", "add", new_path] if
|
|
49
|
+
sh ["git", "add", new_path] if config.commit && new_path
|
|
48
50
|
|
|
49
|
-
config_helper.target.add_system_frameworks
|
|
51
|
+
config_helper.target.add_system_frameworks config.frameworks unless config.frameworks.nil? || config.frameworks.empty?
|
|
50
52
|
|
|
51
53
|
xcodeproj.save
|
|
52
54
|
|
|
53
55
|
case config.sdk_integration_mode
|
|
54
56
|
when :cocoapods
|
|
55
57
|
if File.exist? config.podfile_path
|
|
56
|
-
helper.update_podfile
|
|
58
|
+
helper.update_podfile config
|
|
57
59
|
else
|
|
58
|
-
helper.add_cocoapods
|
|
60
|
+
helper.add_cocoapods config
|
|
59
61
|
end
|
|
60
62
|
when :carthage
|
|
61
63
|
if File.exist? config.cartfile_path
|
|
62
|
-
helper.update_cartfile
|
|
64
|
+
helper.update_cartfile config, xcodeproj
|
|
63
65
|
else
|
|
64
|
-
helper.add_carthage
|
|
66
|
+
helper.add_carthage config
|
|
65
67
|
end
|
|
66
68
|
when :direct
|
|
67
|
-
helper.add_direct
|
|
69
|
+
helper.add_direct config
|
|
68
70
|
end
|
|
69
71
|
|
|
70
|
-
patch_helper.patch_source xcodeproj if
|
|
72
|
+
patch_helper.patch_source xcodeproj if config.patch_source
|
|
71
73
|
|
|
72
|
-
return unless
|
|
74
|
+
return 0 unless config.commit
|
|
73
75
|
|
|
74
76
|
changes = helper.changes.to_a.map { |c| Pathname.new(File.expand_path(c)).relative_path_from(Pathname.pwd).to_s }
|
|
75
77
|
|
|
76
|
-
commit_message =
|
|
78
|
+
commit_message = config.commit if config.commit.kind_of?(String)
|
|
77
79
|
commit_message ||= "[branch_io_cli] Branch SDK integration #{config.relative_path(config.xcodeproj_path)} (#{config.target.name})"
|
|
78
80
|
|
|
79
81
|
sh ["git", "commit", "-qm", commit_message, *changes]
|
|
82
|
+
|
|
83
|
+
0
|
|
80
84
|
end
|
|
81
85
|
# rubocop: enable Metrics/PerceivedComplexity
|
|
82
86
|
|
|
@@ -84,7 +88,7 @@ module BranchIOCLI
|
|
|
84
88
|
# If the git command is not installed, there's not much we can do.
|
|
85
89
|
# Don't want to use verify_git here, which will insist on installing
|
|
86
90
|
# the command. The logic of that method could change.
|
|
87
|
-
return if `which git`.empty? || !config.
|
|
91
|
+
return if `which git`.empty? || !config.confirm
|
|
88
92
|
|
|
89
93
|
unless Dir.exist? ".git"
|
|
90
94
|
`git rev-parse --git-dir > /dev/null 2>&1`
|
|
@@ -4,8 +4,8 @@ module BranchIOCLI
|
|
|
4
4
|
def run!
|
|
5
5
|
valid = true
|
|
6
6
|
|
|
7
|
-
unless
|
|
8
|
-
domains_valid = helper.validate_project_domains(
|
|
7
|
+
unless config.domains.nil? || config.domains.empty?
|
|
8
|
+
domains_valid = helper.validate_project_domains(config.domains)
|
|
9
9
|
|
|
10
10
|
if domains_valid
|
|
11
11
|
say "Project domains match :domains parameter: ✅"
|
|
@@ -27,7 +27,7 @@ module BranchIOCLI
|
|
|
27
27
|
|
|
28
28
|
say "Universal Link configuration passed validation. ✅" if valid
|
|
29
29
|
|
|
30
|
-
valid
|
|
30
|
+
valid ? 0 : 1
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
@@ -4,6 +4,7 @@ require "xcodeproj"
|
|
|
4
4
|
|
|
5
5
|
module BranchIOCLI
|
|
6
6
|
module Configuration
|
|
7
|
+
# rubocop: disable Metrics/ClassLength
|
|
7
8
|
class Configuration
|
|
8
9
|
class << self
|
|
9
10
|
attr_accessor :current
|
|
@@ -14,10 +15,39 @@ module BranchIOCLI
|
|
|
14
15
|
|
|
15
16
|
def defaults
|
|
16
17
|
available_options.inject({}) do |defs, o|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
default_value = o.env_value
|
|
19
|
+
default_value = o.default_value if default_value.nil?
|
|
20
|
+
|
|
21
|
+
next defs if default_value.nil?
|
|
22
|
+
|
|
23
|
+
defs.merge(o.name => default_value)
|
|
19
24
|
end
|
|
20
25
|
end
|
|
26
|
+
|
|
27
|
+
def absolute_path(path)
|
|
28
|
+
return path unless current
|
|
29
|
+
current.absolute_path path
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def relative_path(path)
|
|
33
|
+
return path unless current
|
|
34
|
+
current.relative_path path
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def open_podfile(path)
|
|
38
|
+
return false unless current
|
|
39
|
+
current.open_podfile absolute_path path
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def open_xcodeproj(path)
|
|
43
|
+
return false unless current
|
|
44
|
+
current.open_xcodeproj absolute_path path
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def root
|
|
48
|
+
return nil unless current
|
|
49
|
+
current.root
|
|
50
|
+
end
|
|
21
51
|
end
|
|
22
52
|
|
|
23
53
|
attr_reader :options
|
|
@@ -34,10 +64,12 @@ module BranchIOCLI
|
|
|
34
64
|
|
|
35
65
|
def initialize(options)
|
|
36
66
|
@options = options
|
|
37
|
-
@pod_repo_update = options.pod_repo_update if
|
|
67
|
+
@pod_repo_update = options.pod_repo_update if self.class.available_options.map(&:name).include?(:pod_repo_update)
|
|
68
|
+
|
|
38
69
|
Configuration.current = self
|
|
39
70
|
|
|
40
|
-
|
|
71
|
+
say "\n"
|
|
72
|
+
print_identification
|
|
41
73
|
validate_options
|
|
42
74
|
log
|
|
43
75
|
end
|
|
@@ -54,10 +86,9 @@ EOF
|
|
|
54
86
|
# subclass implementation follows
|
|
55
87
|
end
|
|
56
88
|
|
|
57
|
-
def print_identification
|
|
89
|
+
def print_identification
|
|
58
90
|
say <<EOF
|
|
59
|
-
|
|
60
|
-
<%= color("branch_io #{command} v. #{VERSION}", BOLD) %>
|
|
91
|
+
<%= color("branch_io #{self.class.name.sub(/^.*::(.*?)Configuration$/, '\1').downcase} v. #{VERSION}", BOLD) %>
|
|
61
92
|
|
|
62
93
|
EOF
|
|
63
94
|
end
|
|
@@ -66,21 +97,36 @@ EOF
|
|
|
66
97
|
Helper::BranchHelper
|
|
67
98
|
end
|
|
68
99
|
|
|
100
|
+
def target_name
|
|
101
|
+
target.name.nil? ? nil : target.name
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def root
|
|
105
|
+
return @root if @root
|
|
106
|
+
if workspace
|
|
107
|
+
@root = Pathname.new(workspace_path).dirname
|
|
108
|
+
else
|
|
109
|
+
@root = Pathname.new(xcodeproj_path).dirname
|
|
110
|
+
end
|
|
111
|
+
@root
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def absolute_path(path)
|
|
115
|
+
return nil if path.nil?
|
|
116
|
+
|
|
117
|
+
path = Pathname.new(path) unless path.kind_of? Pathname
|
|
118
|
+
return path.to_s if path.absolute?
|
|
119
|
+
|
|
120
|
+
(root + path).to_s
|
|
121
|
+
end
|
|
122
|
+
|
|
69
123
|
def relative_path(path)
|
|
70
124
|
return nil if path.nil?
|
|
71
125
|
|
|
72
126
|
path = Pathname.new(path) unless path.kind_of? Pathname
|
|
73
127
|
return path.to_s unless path.absolute?
|
|
74
128
|
|
|
75
|
-
|
|
76
|
-
if workspace
|
|
77
|
-
@root = Pathname.new(workspace_path).dirname
|
|
78
|
-
else
|
|
79
|
-
@root = Pathname.new(xcodeproj_path).dirname
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
path.relative_path_from(@root).to_s
|
|
129
|
+
path.relative_path_from(root).to_s
|
|
84
130
|
end
|
|
85
131
|
|
|
86
132
|
# 1. Look for options.xcodeproj.
|
|
@@ -167,12 +213,21 @@ EOF
|
|
|
167
213
|
@sdk_integration_mode = filename == "Podfile" ? :cocoapods : :carthage
|
|
168
214
|
end
|
|
169
215
|
|
|
170
|
-
def open_podfile(path =
|
|
216
|
+
def open_podfile(path = podfile_path)
|
|
171
217
|
@podfile = Pod::Podfile.from_file path
|
|
172
218
|
@podfile_path = path
|
|
173
219
|
@sdk_integration_mode = :cocoapods
|
|
174
220
|
true
|
|
175
|
-
rescue
|
|
221
|
+
rescue Pod::PlainInformative => e
|
|
222
|
+
say e.message
|
|
223
|
+
false
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def open_xcodeproj(path = xcodeproj_path)
|
|
227
|
+
@xcodeproj = Xcodeproj::Project.open path
|
|
228
|
+
@xcodeproj_path = path
|
|
229
|
+
true
|
|
230
|
+
rescue Xcodeproj::PlainInformative => e
|
|
176
231
|
say e.message
|
|
177
232
|
false
|
|
178
233
|
end
|
|
@@ -285,7 +340,7 @@ EOF
|
|
|
285
340
|
return @bridging_header_path if @bridging_header_path
|
|
286
341
|
|
|
287
342
|
return nil unless target
|
|
288
|
-
path =
|
|
343
|
+
path = target.expanded_build_setting "SWIFT_OBJC_BRIDGING_HEADER", configuration
|
|
289
344
|
return nil unless path
|
|
290
345
|
|
|
291
346
|
@bridging_header_path = File.expand_path path, File.dirname(xcodeproj_path)
|
|
@@ -328,14 +383,96 @@ EOF
|
|
|
328
383
|
all_options = self.class.available_options.map(&:name)
|
|
329
384
|
return super unless all_options.include?(method_sym)
|
|
330
385
|
|
|
386
|
+
# Define an attr_reader for this method
|
|
331
387
|
self.class.send :define_method, method_sym do
|
|
332
|
-
|
|
333
|
-
value = instance_variable_get ivar
|
|
334
|
-
value
|
|
388
|
+
instance_variable_get "@#{method_sym}"
|
|
335
389
|
end
|
|
336
390
|
|
|
337
391
|
send method_sym
|
|
338
392
|
end
|
|
393
|
+
|
|
394
|
+
# Prompt the user to confirm the configuration or edit.
|
|
395
|
+
def confirm_with_user
|
|
396
|
+
confirmed = Helper::Util.confirm "Is this OK? ", true
|
|
397
|
+
return if confirmed
|
|
398
|
+
|
|
399
|
+
loop do
|
|
400
|
+
Helper::Util.clear
|
|
401
|
+
|
|
402
|
+
print_identification
|
|
403
|
+
|
|
404
|
+
say "<%= color('The following options may be adjusted before continuing.', BOLD) %>"
|
|
405
|
+
choice = choose do |menu|
|
|
406
|
+
self.class.available_options.reject(&:skip_confirmation).each do |option|
|
|
407
|
+
value = send option.confirm_symbol
|
|
408
|
+
menu.choice "#{option.label}: #{option.display_value(value)}"
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
menu.choice "Accept and continue"
|
|
412
|
+
menu.choice "Quit"
|
|
413
|
+
menu.readline = true
|
|
414
|
+
menu.prompt = "What would you like to do?"
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
Helper::Util.clear
|
|
418
|
+
|
|
419
|
+
print_identification
|
|
420
|
+
|
|
421
|
+
if (option = self.class.available_options.find { |o| choice =~ /^#{Regexp.quote(o.label)}/ })
|
|
422
|
+
loop do
|
|
423
|
+
break if prompt_for_option(option)
|
|
424
|
+
say "Invalid value for option.\n\n"
|
|
425
|
+
end
|
|
426
|
+
elsif choice =~ /^Accept/
|
|
427
|
+
log
|
|
428
|
+
return
|
|
429
|
+
else
|
|
430
|
+
exit(0)
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
def prompt_for_option(option)
|
|
436
|
+
say "<%= color('#{option.label}', BOLD) %>\n\n"
|
|
437
|
+
say "#{option.description}\n\n"
|
|
438
|
+
value = send option.confirm_symbol
|
|
439
|
+
say "<%= color('Type', BOLD) %>: #{option.ui_type}\n"
|
|
440
|
+
say "<%= color('Current value', BOLD) %>: #{option.display_value(value)}"
|
|
441
|
+
say "<%= color('Example', BOLD) %>: #{option.example}" if option.example
|
|
442
|
+
say "\n"
|
|
443
|
+
|
|
444
|
+
valid_values = option.valid_values
|
|
445
|
+
|
|
446
|
+
if valid_values && !option.type.nil? && option.type != Array
|
|
447
|
+
new_value = choose(*valid_values) do |menu|
|
|
448
|
+
menu.readline = true
|
|
449
|
+
menu.prompt = "Please choose from this list. "
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
# Valid because chosen from list
|
|
453
|
+
elsif valid_values && option.type == Array
|
|
454
|
+
# There seems to be a problem with using menu.gather, so we do this.
|
|
455
|
+
valid_values.each do |v|
|
|
456
|
+
say "#{v}\n"
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
new_value = ask "Please enter one or more of the above, separated by commas: " do |q|
|
|
460
|
+
q.readline = true
|
|
461
|
+
q.completion = valid_values
|
|
462
|
+
end.split(",") # comma-split with Array not working
|
|
463
|
+
elsif option.type.nil?
|
|
464
|
+
new_value = Helper::Util.confirm "#{option.label}? ", value
|
|
465
|
+
else
|
|
466
|
+
new_value = ask "Please enter a new value for #{option.label}: ", option.type
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
new_value = option.convert new_value
|
|
470
|
+
|
|
471
|
+
return false unless option.valid?(new_value)
|
|
472
|
+
instance_variable_set "@#{option.confirm_symbol}", new_value
|
|
473
|
+
true
|
|
474
|
+
end
|
|
339
475
|
end
|
|
476
|
+
# rubocop: enable Metrics/ClassLength
|
|
340
477
|
end
|
|
341
478
|
end
|