branch_io_cli 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +78 -30
  3. data/lib/assets/completions/completion.bash +1 -1
  4. data/lib/assets/completions/completion.zsh +1 -1
  5. data/lib/assets/templates/command.erb +31 -0
  6. data/lib/assets/templates/program_description.erb +2 -0
  7. data/lib/assets/templates/report_description.erb +4 -0
  8. data/lib/assets/templates/setup_description.erb +52 -0
  9. data/lib/assets/templates/validate_description.erb +18 -0
  10. data/lib/branch_io_cli.rb +1 -0
  11. data/lib/branch_io_cli/cli.rb +50 -147
  12. data/lib/branch_io_cli/command/command.rb +28 -6
  13. data/lib/branch_io_cli/command/report_command.rb +1 -1
  14. data/lib/branch_io_cli/command/setup_command.rb +4 -7
  15. data/lib/branch_io_cli/command/validate_command.rb +0 -2
  16. data/lib/branch_io_cli/configuration.rb +2 -0
  17. data/lib/branch_io_cli/configuration/configuration.rb +27 -1
  18. data/lib/branch_io_cli/configuration/option.rb +28 -0
  19. data/lib/branch_io_cli/configuration/option_wrapper.rb +33 -0
  20. data/lib/branch_io_cli/configuration/report_configuration.rb +83 -7
  21. data/lib/branch_io_cli/configuration/setup_configuration.rb +142 -9
  22. data/lib/branch_io_cli/configuration/validate_configuration.rb +30 -1
  23. data/lib/branch_io_cli/core_ext/io.rb +5 -2
  24. data/lib/branch_io_cli/format.rb +15 -0
  25. data/lib/branch_io_cli/format/commander_format.rb +21 -0
  26. data/lib/branch_io_cli/format/markdown_format.rb +60 -0
  27. data/lib/branch_io_cli/helper/ios_helper.rb +14 -14
  28. data/lib/branch_io_cli/helper/methods.rb +2 -2
  29. data/lib/branch_io_cli/rake_task.rb +26 -54
  30. data/lib/branch_io_cli/version.rb +1 -1
  31. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d57e3295339b988ee4f835a92154eb15e45ae1df5655930902ebc5c43f1a33e0
4
- data.tar.gz: 6b9b929afa148c9aa389116ac73e8d0eb8143ea5fed06285e389819371496c24
3
+ metadata.gz: c19de7b1fee926331d25dec07b8f5af3c3ddd099d7a935bdf724499da2dc0684
4
+ data.tar.gz: 8777a15c765285fcdc8de2db03c26bae564c7f3557d2bc1e2bdf5b593e99595e
5
5
  SHA512:
6
- metadata.gz: 0f8a5e5132646571ed123b8546b8ceee45e998d0cc06356854d133c93cf544313302100f6058f22ecafa5a859f1459fd0c89b983745d3fadd865c2f95d7b0ee4
7
- data.tar.gz: b37bd6a57304fb87f0ff721e30d1d7281bf52f1b0cfd6872b23b6cbd46494a4b5345b1f3925dfe6fc322f4365606b053aacb28aaad9b1875e5eae93d889dfe01
6
+ metadata.gz: 6ea8a70c65a8234a83f541c1c67191e26d2dd20e0e20f4bb5a6a645e667b3db37aca91c54a9071cbaef13977697f37f4cab3aa9c7845059eb201f7d0b5391be5
7
+ data.tar.gz: d31b0cff7755187e94f6e7ce9be04f27b83ca3fee7b52e1db95c9c2f3f365fdc8d5bfffa2881e3e2b041e949047edd25595ac629cbc38093e634654e421ecec1
data/README.md CHANGED
@@ -59,6 +59,9 @@ Currently command-line completion for bash is much more extensive than for zsh.
59
59
 
60
60
  ## Commands
61
61
 
62
+ <!-- The following is generated. Do not edit by hand. Run rake readme to -->
63
+ <!-- regenerate this section. -->
64
+ <!-- BEGIN COMMAND REFERENCE -->
62
65
  ### Setup command
63
66
 
64
67
  ```bash
@@ -98,7 +101,9 @@ This can be suppressed using `--no-patch-source`.
98
101
 
99
102
  #### Prerequisites
100
103
 
101
- Before using this command, make sure to set up your app in the [Branch Dashboard](https://dashboard.branch.io). See https://docs.branch.io/pages/dashboard/integrate/ for details. To use the `setup` command, you need:
104
+ Before using this command, make sure to set up your app in the Branch Dashboard
105
+ (https://dashboard.branch.io). See https://docs.branch.io/pages/dashboard/integrate/
106
+ for details. To use the `setup` command, you need:
102
107
 
103
108
  - Branch key(s), either live, test or both
104
109
  - Domain name(s) used for Branch links
@@ -109,6 +114,14 @@ the `pod` or `carthage` command may be required. If not found, the CLI will
109
114
  offer to install and set up these command-line tools for you. Alternately, you can arrange
110
115
  that the relevant commands are available in your `PATH`.
111
116
 
117
+ All parameters are optional. A live key or test key, or both is required, as well
118
+ as at least one domain. Specify `--live-key`, `--test-key` or both and `--app-link-subdomain`,
119
+ `--domains` or both. If these are not specified, this command will prompt you
120
+ for this information.
121
+
122
+ See https://github.com/BranchMetrics/branch_io_cli#setup-command for more information.
123
+
124
+
112
125
  #### Options
113
126
 
114
127
  |Option|Description|
@@ -118,77 +131,92 @@ that the relevant commands are available in your `PATH`.
118
131
  |-t, --trace|Prints a stack trace when exceptions are raised|
119
132
  |-L, --live-key key_live_xxxx|Branch live key|
120
133
  |-T, --test-key key_test_yyyy|Branch test key|
121
- |--app-link-subdomain myapp|Branch app.link subdomain, e.g. myapp for myapp.app.link|
122
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|
123
136
  |-U, --uri-scheme myurischeme[://]|Custom URI scheme used in the Branch Dashboard for this app|
124
137
  |-s, --setting [BRANCH_KEY_SETTING]|Use a custom build setting for the Branch key (default: Use Info.plist)|
125
- |--test-configurations|List of configurations that use the test key with a custom build setting (default: Debug configurations)|
138
+ |--test-configurations config1,config2|List of configurations that use the test key with a custom build setting (default: Debug configurations)|
126
139
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
127
140
  |--target MyAppTarget|Name of a target to modify in the Xcode project|
128
141
  |--podfile /path/to/Podfile|Path to the Podfile for the project|
129
142
  |--cartfile /path/to/Cartfile|Path to the Cartfile for the project|
130
- |--carthage-command <command>|Command to use when installing from Carthage (default: update --platform ios)|
143
+ |--carthage-command <command>|Command to run when installing from Carthage (default: update --platform ios)|
131
144
  |--frameworks AdSupport,CoreSpotlight,SafariServices|Comma-separated list of system frameworks to add to the project|
132
145
  |--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|
133
146
  |--[no-]validate|Validate Universal Link configuration (default: yes)|
134
147
  |--[no-]force|Update project even if Universal Link validation fails (default: no)|
135
148
  |--[no-]add-sdk|Add the Branch framework to the project (default: yes)|
136
149
  |--[no-]patch-source|Add Branch SDK calls to the AppDelegate (default: yes)|
137
- |--[no-]commit [message]|Commit the results to Git (default: no)|
150
+ |--commit [message]|Commit the results to Git|
151
+ |--[no-]check-repo-changes|Check for uncommitted changes to a git repo (default: yes)|
138
152
 
139
- All parameters are optional. A live key or test key, or both is required, as well as at least one domain.
140
- Specify --live-key, --test-key or both and --app-link-subdomain, --domains or both. If these are not
141
- specified, this command will prompt you for the information.
142
153
 
143
154
  #### Examples
144
155
 
156
+
145
157
  ##### Test without validation (can use dummy keys and domains)
146
158
 
147
159
  ```bash
148
160
  branch_io setup -L key_live_xxxx -D myapp.app.link --no-validate
149
161
  ```
150
162
 
163
+
151
164
  ##### Use both live and test keys
152
165
 
153
166
  ```bash
154
167
  branch_io setup -L key_live_xxxx -T key_test_yyyy -D myapp.app.link
155
168
  ```
156
169
 
170
+
157
171
  ##### Use custom or non-Branch domains
158
172
 
159
173
  ```bash
160
174
  branch_io setup -D myapp.app.link,example.com,www.example.com
161
175
  ```
162
176
 
177
+
163
178
  ##### Avoid pod repo update
164
179
 
165
180
  ```bash
166
181
  branch_io setup --no-pod-repo-update
167
182
  ```
168
183
 
184
+
169
185
  ##### Install using carthage bootstrap
170
186
 
171
187
  ```bash
172
188
  branch_io --carthage-command "bootstrap --no-use-binaries"
173
189
  ```
174
190
 
191
+
192
+
193
+
175
194
  ### Validate command
176
195
 
177
196
  ```bash
178
197
  branch_io validate [OPTIONS]
179
198
  ```
180
199
 
181
- This command validates all Universal Link domains configured in a project without making any modification.
182
- It validates both Branch and non-Branch domains. Unlike web-based Universal Link validators,
183
- this command operates directly on the project. It finds the bundle and
184
- signing team identifiers in the project as well as the app's Associated Domains.
185
- It requests the apple-app-site-association file for each domain and validates
186
- the file against the project's settings.
200
+ This command validates all Universal Link domains configured in a project without making any
201
+ modification. It validates both Branch and non-Branch domains. Unlike web-based Universal
202
+ Link validators, this command operates directly on the project. It finds the bundle and
203
+ signing team identifiers in the project as well as the app's Associated Domains. It requests
204
+ the apple-app-site-association file for each domain and validates the file against the
205
+ project's settings.
187
206
 
188
207
  Only app targets are supported for this command. By default, it will validate the first.
189
208
  If your project has multiple app targets, specify the `--target` option to validate other
190
209
  targets.
191
210
 
211
+ All parameters are optional. If `--domains` is specified, the list of Universal Link domains in
212
+ the Associated Domains entitlement must exactly match this list, without regard to order. If
213
+ no `--domains` are provided, validation passes if at least one Universal Link domain is
214
+ configured and passes validation, and no Universal Link domain is present that does not pass
215
+ validation.
216
+
217
+ See https://github.com/BranchMetrics/branch_io_cli#validate-command for more information.
218
+
219
+
192
220
  #### Options
193
221
 
194
222
  |Option|Description|
@@ -196,18 +224,13 @@ targets.
196
224
  |-h, --help|Prints a list of commands or help for each command|
197
225
  |-v, --version|Prints the current version of the CLI|
198
226
  |-t, --trace|Prints a stack trace when exceptions are raised|
199
- |-D, --domains example.com,www.example.com|Comma-separated list of domains. May include app.link subdomains.|
227
+ |-D, --domains example.com,www.example.com|Comma-separated list of domains to validate (Branch domains or non-Branch domains) (default: [])|
200
228
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
201
- |--target MyAppTarget|Name of a target to modify in the Xcode project|
229
+ |--target MyAppTarget|Name of a target to validate in the Xcode project|
230
+
202
231
 
203
- All parameters are optional. If `--domains` is specified, the list of Universal Link domains in the
204
- Associated Domains entitlement must exactly match this list, without regard to order. If no `--domains`
205
- are provided, validation passes if at least one Universal Link domain is configured and passes validation,
206
- and no Universal Link domain is present that does not pass validation.
207
232
 
208
- #### Return value
209
233
 
210
- If validation passes, this command returns 0. If validation fails, it returns 1.
211
234
 
212
235
  ### Report command
213
236
 
@@ -220,6 +243,7 @@ _Work in progress_
220
243
  This command optionally cleans and then builds a workspace or project, generating a verbose
221
244
  report with additional diagnostic information suitable for opening a support ticket.
222
245
 
246
+
223
247
  #### Options
224
248
 
225
249
  |Option|Description|
@@ -229,18 +253,42 @@ report with additional diagnostic information suitable for opening a support tic
229
253
  |-t, --trace|Prints a stack trace when exceptions are raised|
230
254
  |--workspace MyProject.xcworkspace|Path to an Xcode workspace|
231
255
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project|
232
- |--target MyAppTarget|Name of a target to modify in the Xcode project|
233
- |--scheme MyAppScheme|Name of a scheme to build|
234
- |--configuration Debug/Release/CustomConfig|Name of a build configuration (default: Scheme-dependent)|
235
- |--sdk iphonesimulator|Name of an SDK to use with xcodebuild (default: iphonesimulator)|
236
- |--[no-]clean|Clean before building (default: yes)|
237
- |-H, --[no-]header-only|Show a diagnostic header and exit without cleaning or building (default: no)|
238
- |--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|
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)|
239
260
  |--podfile /path/to/Podfile|Path to the Podfile for the project|
240
261
  |--cartfile /path/to/Cartfile|Path to the Cartfile for the project|
241
- |-o, --out ./report.txt|Path to use for the generated report (default: ./report.txt)|
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)|
266
+
267
+
268
+
269
+
270
+
271
+ <!-- END COMMAND REFERENCE -->
242
272
 
243
273
  ## Examples
244
274
 
245
275
  See the [examples](./examples) folder for several example projects that can be
246
276
  used to exercise the CLI.
277
+
278
+ ## Rake task
279
+
280
+ You can use these commands easily with Rake:
281
+
282
+ ```Ruby
283
+ require 'branch_io_cli/rake_task'
284
+ BranchIOCLI::RakeTask.new
285
+ ```
286
+
287
+ This defines the tasks `branch:report`, `branch:setup` and `branch:validate`.
288
+ Each takes a path or an array of paths for a project directory as the first
289
+ argument, followed by an options Hash with keys derived from the command-line
290
+ arguments. For example:
291
+
292
+ ```Ruby
293
+ Rake::Task["branch:validate"].invoke ".", domains: %w(example.com www.example.com)
294
+ ```
@@ -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"
16
+ setup_opts="$setup_opts --test-configurations --no-test-configurations --no-check-repo-changes"
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"
9
+ opts="$opts --test-configurations --no-test-configurations --no-check-repo-changes"
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
 
@@ -0,0 +1,31 @@
1
+ <%= header "#{@command.command_name.to_s.capitalize} command", 3 %>
2
+
3
+ ```bash
4
+ branch_io <%= @command.command_name %> [OPTIONS]
5
+ ```
6
+
7
+ <%= render "#{@command.command_name}_description" %>
8
+
9
+ <%= header "Options", 4 %>
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|
16
+ <%= table_options %>
17
+
18
+ <% if @command.respond_to?(:examples) && !@command.examples.blank? %>
19
+ <%= header "Examples", 4 %>
20
+ <% @command.examples.each_key do |text| %>
21
+ <% example = @command.examples[text] %>
22
+ <%= header text, 5 %>
23
+
24
+ ```bash
25
+ <%= example %>
26
+ ```
27
+ <% end %>
28
+ <% end %>
29
+
30
+ <% if @command.respond_to?(:return_value) && !@command.return_value.nil? %>
31
+ <% end %>
@@ -0,0 +1,2 @@
1
+ Command-line tool to integrate the Branch SDK into mobile app projects (currently
2
+ iOS only) and validate Universal Link domains
@@ -0,0 +1,4 @@
1
+ <%= italics 'Work in progress' %>
2
+
3
+ This command optionally cleans and then builds a workspace or project, generating a verbose
4
+ report with additional diagnostic information suitable for opening a support ticket.
@@ -0,0 +1,52 @@
1
+ Integrates the Branch SDK into a native app project. This currently supports iOS only.
2
+ It will infer the project location if there is exactly one .xcodeproj anywhere under
3
+ the current directory, excluding any in a Pods or Carthage folder. Otherwise, specify
4
+ the project location using the <%= option :xcodeproj %> option, or the CLI will prompt you for the
5
+ location.
6
+
7
+ If a Podfile or Cartfile is detected, the Branch SDK will be added to the relevant
8
+ configuration file and the dependencies updated to include the Branch framework.
9
+ This behavior may be suppressed using <%= option :no_add_sdk %>. If no Podfile or Cartfile
10
+ is found, and Branch.framework is not already among the project's dependencies,
11
+ you will be prompted for a number of choices, including setting up CocoaPods or
12
+ Carthage for the project or directly installing the Branch.framework.
13
+
14
+ By default, all supplied Universal Link domains are validated. If validation passes,
15
+ the setup continues. If validation fails, no further action is taken. Suppress
16
+ validation using <%= option :no_validate %> or force changes when validation fails using
17
+ <%= option :force %>.
18
+
19
+ By default, this command will look for the first app target in the project. Test
20
+ targets are not supported. To set up an extension target, supply the <%= option :target %> option.
21
+
22
+ All relevant target settings are modified. The Branch keys are added to the Info.plist,
23
+ along with the <%= highlight 'branch_universal_link_domains' %> key for custom domains (when <%= option :domains %>
24
+ is used). For app targets, all domains are added to the project's Associated Domains
25
+ entitlement. An entitlements file is also added for app targets if none is found.
26
+ Optionally, if <%= option :frameworks %> is specified, this command can add a list of system
27
+ frameworks to the target's dependencies (e.g., AdSupport, CoreSpotlight, SafariServices).
28
+
29
+ A language-specific patch is applied to the AppDelegate (Swift or Objective-C).
30
+ This can be suppressed using <%= option :no_patch_source %>.
31
+
32
+ <%= header 'Prerequisites', 4 %>
33
+
34
+ Before using this command, make sure to set up your app in the Branch Dashboard
35
+ (https://dashboard.branch.io). See https://docs.branch.io/pages/dashboard/integrate/
36
+ for details. To use the <%= highlight 'setup' %> command, you need:
37
+
38
+ - Branch key(s), either live, test or both
39
+ - Domain name(s) used for Branch links
40
+ - Location of your Xcode project (may be inferred in simple projects)
41
+
42
+ If using the <%= option :commit %> option, <%= highlight 'git' %> is required. If not using <%= option :no_add_sdk %>,
43
+ the <%= highlight 'pod' %> or <%= highlight 'carthage' %> command may be required. If not found, the CLI will
44
+ offer to install and set up these command-line tools for you. Alternately, you can arrange
45
+ that the relevant commands are available in your <%= highlight 'PATH' %>.
46
+
47
+ All parameters are optional. A live key or test key, or both is required, as well
48
+ as at least one domain. Specify <%= option :live_key %>, <%= option :test_key %> or both and <%= option :app_link_subdomain %>,
49
+ <%= option :domains %> or both. If these are not specified, this command will prompt you
50
+ for this information.
51
+
52
+ See https://github.com/BranchMetrics/branch_io_cli#setup-command for more information.
@@ -0,0 +1,18 @@
1
+ This command validates all Universal Link domains configured in a project without making any
2
+ modification. It validates both Branch and non-Branch domains. Unlike web-based Universal
3
+ Link validators, this command operates directly on the project. It finds the bundle and
4
+ signing team identifiers in the project as well as the app's Associated Domains. It requests
5
+ the apple-app-site-association file for each domain and validates the file against the
6
+ project's settings.
7
+
8
+ Only app targets are supported for this command. By default, it will validate the first.
9
+ If your project has multiple app targets, specify the <%= option :target %> option to validate other
10
+ targets.
11
+
12
+ All parameters are optional. If <%= option :domains %> is specified, the list of Universal Link domains in
13
+ the Associated Domains entitlement must exactly match this list, without regard to order. If
14
+ no <%= option :domains %> are provided, validation passes if at least one Universal Link domain is
15
+ configured and passes validation, and no Universal Link domain is present that does not pass
16
+ validation.
17
+
18
+ See https://github.com/BranchMetrics/branch_io_cli#validate-command for more information.
@@ -2,5 +2,6 @@ require "branch_io_cli/cli"
2
2
  require "branch_io_cli/command"
3
3
  require "branch_io_cli/configuration"
4
4
  require "branch_io_cli/core_ext"
5
+ require "branch_io_cli/format"
5
6
  require "branch_io_cli/helper"
6
7
  require "branch_io_cli/version"
@@ -1,116 +1,31 @@
1
1
  require "rubygems"
2
2
  require "commander"
3
+ require "branch_io_cli/format"
3
4
 
4
5
  module BranchIOCLI
5
6
  class CLI
6
7
  include Commander::Methods
8
+ include Format::CommanderFormat
7
9
 
8
10
  def run
9
11
  program :name, "Branch.io command-line interface"
10
12
  program :version, VERSION
11
- program :description, <<EOF
12
- Command-line tool to integrate the Branch SDK into mobile app projects (currently
13
- iOS only) and validate Universal Link domains
14
- EOF
13
+ program :description, render(:program_description)
15
14
 
16
15
  command :setup do |c|
17
16
  c.syntax = "branch_io setup [OPTIONS]"
18
17
  c.summary = "Integrates the Branch SDK into a native app project"
19
- c.description = <<EOF
20
- Integrates the Branch SDK into a native app project. This currently supports iOS only.
21
- It will infer the project location if there is exactly one .xcodeproj anywhere under
22
- the current directory, excluding any in a Pods or Carthage folder. Otherwise, specify
23
- the project location using the <%= color('--xcodeproj', BOLD) %> option, or the CLI will prompt you for the
24
- location.
25
-
26
- If a Podfile or Cartfile is detected, the Branch SDK will be added to the relevant
27
- configuration file and the dependencies updated to include the Branch framework.
28
- This behavior may be suppressed using <%= color('--no-add-sdk', BOLD) %>. If no Podfile or Cartfile
29
- is found, and Branch.framework is not already among the project's dependencies,
30
- you will be prompted for a number of choices, including setting up CocoaPods or
31
- Carthage for the project or directly installing the Branch.framework.
32
-
33
- By default, all supplied Universal Link domains are validated. If validation passes,
34
- the setup continues. If validation fails, no further action is taken. Suppress
35
- validation using <%= color('--no-validate', BOLD) %> or force changes when validation fails using
36
- <%= color('--force', BOLD) %>.
37
-
38
- By default, this command will look for the first app target in the project. Test
39
- targets are not supported. To set up an extension target, supply the <%= color('--target', BOLD) %> option.
40
-
41
- All relevant target settings are modified. The Branch keys are added to the Info.plist,
42
- along with the <%= color('branch_universal_link_domains', BOLD) %> key for custom domains (when <%= color('--domains', BOLD) %>
43
- is used). For app targets, all domains are added to the project's Associated Domains
44
- entitlement. An entitlements file is also added for app targets if none is found.
45
- Optionally, if <%= color('--frameworks', BOLD) %> is specified, this command can add a list of system
46
- frameworks to the target's dependencies (e.g., AdSupport, CoreSpotlight, SafariServices).
47
-
48
- A language-specific patch is applied to the AppDelegate (Swift or Objective-C).
49
- This can be suppressed using <%= color('--no-patch-source', BOLD) %>.
50
-
51
- <%= color('Prerequisites', BOLD) %>
52
-
53
- Before using this command, make sure to set up your app in the Branch Dashboard
54
- (https://dashboard.branch.io). See https://docs.branch.io/pages/dashboard/integrate/
55
- for details. To use the <%= color('setup', BOLD) %> command, you need:
56
-
57
- - Branch key(s), either live, test or both
58
- - Domain name(s) used for Branch links
59
- - Location of your Xcode project (may be inferred in simple projects)
60
-
61
- If using the <%= color('--commit', BOLD) %> option, <%= color('git', BOLD) %> is required. If not using <%= color('--no-add-sdk', BOLD) %>,
62
- the <%= color('pod', BOLD) %> or <%= color('carthage', BOLD) %> command may be required. If not found, the CLI will
63
- offer to install and set up these command-line tools for you. Alternately, you can arrange
64
- that the relevant commands are available in your <%= color('PATH', BOLD) %>.
65
-
66
- All parameters are optional. A live key or test key, or both is required, as well
67
- as at least one domain. Specify <%= color('--live-key', BOLD) %>, <%= color('--test-key', BOLD) %> or both and <%= color('--app-link-subdomain', BOLD) %>,
68
- <%= color('--domains', BOLD) %> or both. If these are not specified, this command will prompt you
69
- for this information.
70
-
71
- See https://github.com/BranchMetrics/branch_io_cli#setup-command for more information.
72
- EOF
73
-
74
- # Required Branch params
75
- c.option "-L", "--live-key key_live_xxxx", String, "Branch live key"
76
- c.option "-T", "--test-key key_test_yyyy", String, "Branch test key"
77
- c.option "--app-link-subdomain myapp", String, "Branch app.link subdomain, e.g. myapp for myapp.app.link"
78
- c.option "-D", "--domains example.com,www.example.com", Array, "Comma-separated list of custom domain(s) or non-Branch domain(s)"
79
- c.option "-U", "--uri-scheme myurischeme[://]", String, "Custom URI scheme used in the Branch Dashboard for this app"
80
- c.option "-s", "--setting [BRANCH_KEY_SETTING]", String, "Use a custom build setting for the Branch key (default: Use Info.plist)"
81
- c.option "--[no-]test-configurations [config1,config2]", Array, "List of configurations that use the test key with a custom build setting (default: Debug configurations)"
82
-
83
- c.option "--xcodeproj MyProject.xcodeproj", String, "Path to an Xcode project to update"
84
- c.option "--target MyAppTarget", String, "Name of a target to modify in the Xcode project"
85
- c.option "--podfile /path/to/Podfile", String, "Path to the Podfile for the project"
86
- c.option "--cartfile /path/to/Cartfile", String, "Path to the Cartfile for the project"
87
- c.option "--carthage-command <command>", String, "Command to run when installing from Carthage (default: update --platform ios)"
88
- c.option "--frameworks AdSupport,CoreSpotlight,SafariServices", Array, "Comma-separated list of system frameworks to add to the project"
89
-
90
- c.option "--[no-]pod-repo-update", "Update the local podspec repo before installing (default: yes)"
91
- c.option "--[no-]validate", "Validate Universal Link configuration (default: yes)"
92
- c.option "--[no-]force", "Update project even if Universal Link validation fails (default: no)"
93
- c.option "--[no-]add-sdk", "Add the Branch framework to the project (default: yes)"
94
- c.option "--[no-]patch-source", "Add Branch SDK calls to the AppDelegate (default: yes)"
95
- c.option "--[no-]commit [message]", String, "Commit the results to Git (default: no)"
96
-
97
- c.example "Test without validation (can use dummy keys and domains)", "branch_io setup -L key_live_xxxx -D myapp.app.link --no-validate"
98
- c.example "Use both live and test keys", "branch_io setup -L key_live_xxxx -T key_test_yyyy -D myapp.app.link"
99
- c.example "Use custom or non-Branch domains", "branch_io setup -D myapp.app.link,example.com,www.example.com"
100
- c.example "Avoid pod repo update", "branch_io setup --no-pod-repo-update"
101
- c.example "Install using carthage bootstrap", "branch_io --carthage-command \"bootstrap --no-use-binaries\""
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
102
26
 
103
27
  c.action do |args, options|
104
- options.default(
105
- # Defaults for boolean options
106
- pod_repo_update: true,
107
- validate: true,
108
- force: false,
109
- add_sdk: true,
110
- patch_source: true,
111
- commit: false,
112
- carthage_command: "update --platform ios"
113
- )
28
+ options.default Configuration::SetupConfiguration.defaults
114
29
  Command::SetupCommand.new(options).run!
115
30
  end
116
31
  end
@@ -118,32 +33,12 @@ EOF
118
33
  command :validate do |c|
119
34
  c.syntax = "branch_io validate [OPTIONS]"
120
35
  c.summary = "Validates all Universal Link domains configured in a project"
121
- c.description = <<EOF
122
- This command validates all Universal Link domains configured in a project without making any
123
- modification. It validates both Branch and non-Branch domains. Unlike web-based Universal
124
- Link validators, this command operates directly on the project. It finds the bundle and
125
- signing team identifiers in the project as well as the app's Associated Domains. It requests
126
- the apple-app-site-association file for each domain and validates the file against the
127
- project's settings.
128
-
129
- Only app targets are supported for this command. By default, it will validate the first.
130
- If your project has multiple app targets, specify the <%= color('--target', BOLD) %> option to validate other
131
- targets.
132
-
133
- All parameters are optional. If <%= color('--domains', BOLD) %> is specified, the list of Universal Link domains in
134
- the Associated Domains entitlement must exactly match this list, without regard to order. If
135
- no <%= color('--domains', BOLD) %> are provided, validation passes if at least one Universal Link domain is
136
- configured and passes validation, and no Universal Link domain is present that does not pass
137
- validation.
138
-
139
- See https://github.com/BranchMetrics/branch_io_cli#validate-command for more information.
140
- EOF
141
-
142
- c.option "-D", "--domains example.com,www.example.com", Array, "Comma-separated list of domains to validate (Branch domains or non-Branch domains)"
143
- c.option "--xcodeproj MyProject.xcodeproj", String, "Path to an Xcode project to update"
144
- c.option "--target MyAppTarget", String, "Name of a target to modify in the Xcode project"
36
+ c.description = render :validate_description
37
+
38
+ add_options_for_command :validate, c
145
39
 
146
40
  c.action do |args, options|
41
+ options.default Configuration::ValidateConfiguration.defaults
147
42
  valid = Command::ValidateCommand.new(options).run!
148
43
  exit_code = valid ? 0 : 1
149
44
  exit exit_code
@@ -153,39 +48,47 @@ EOF
153
48
  command :report do |c|
154
49
  c.syntax = "branch_io report [OPTIONS]"
155
50
  c.summary = "Generate and optionally submit a build diagnostic report."
156
- c.description = <<EOF
157
- <%= color('Work in progress', BOLD) %>
158
-
159
- This command optionally cleans and then builds a workspace or project, generating a verbose
160
- report with additional diagnostic information suitable for opening a support ticket.
161
- EOF
162
-
163
- c.option "--xcodeproj MyProject.xcodeproj", String, "Path to an Xcode project"
164
- c.option "--workspace MyProject.xcworkspace", String, "Path to an Xcode workspace"
165
- c.option "--scheme MyProjectScheme", String, "A scheme from the project or workspace to build"
166
- c.option "--target MyProjectTarget", String, "A target to build"
167
- c.option "--configuration Debug|Release|CustomConfigName", String, "The build configuration to use (default: Scheme-dependent)"
168
- c.option "--sdk iphonesimulator", String, "Passed as -sdk to xcodebuild (default: iphonesimulator)"
169
- c.option "--podfile /path/to/Podfile", String, "Path to the Podfile for the project"
170
- c.option "--cartfile /path/to/Cartfile", String, "Path to the Cartfile for the project"
171
- c.option "--[no-]clean", "Clean before attempting to build (default: yes)"
172
- c.option "-H", "--[no-]header-only", "Write a report header to standard output and exit"
173
- c.option "--[no-]pod-repo-update", "Update the local podspec repo before installing (default: yes)"
174
- c.option "-o", "--out ./report.txt", String, "Report output path (default: ./report.txt)"
51
+ c.description = render :report_description
52
+
53
+ add_options_for_command :report, c
175
54
 
176
55
  c.action do |args, options|
177
- options.default(
178
- clean: true,
179
- header_only: false,
180
- sdk: "iphonesimulator",
181
- out: "./report.txt",
182
- pod_repo_update: true
183
- )
56
+ options.default Configuration::ReportConfiguration.defaults
184
57
  Command::ReportCommand.new(options).run!
185
58
  end
186
59
  end
187
60
 
188
61
  run!
189
62
  end
63
+
64
+ def add_options_for_command(name, c)
65
+ configuration_class = Object.const_get("BranchIOCLI")
66
+ .const_get("Configuration")
67
+ .const_get("#{name.to_s.capitalize}Configuration")
68
+ available_options = configuration_class.available_options
69
+ available_options.each do |option|
70
+ args = option.aliases
71
+ declaration = "--"
72
+ declaration += "[no-]" if option.negatable
73
+ declaration += "#{option.name.to_s.gsub(/_/, '-')} "
74
+ if option.example
75
+ declaration += "[" if option.argument_optional
76
+ declaration += option.example
77
+ declaration += "]" if option.argument_optional
78
+ end
79
+ args << declaration
80
+ args << option.type if option.type
81
+
82
+ if option.type.nil?
83
+ default_value = option.default_value ? "yes" : "no"
84
+ else
85
+ default_value = option.default_value
86
+ end
87
+
88
+ default_string = default_value ? " (default: #{default_value})" : nil
89
+ args << "#{option.description}#{default_string}"
90
+ c.option(*args)
91
+ end
92
+ end
190
93
  end
191
94
  end