shopify-cli 1.0.3 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +1 -1
  3. data/.travis.yml +3 -2
  4. data/CHANGELOG.md +20 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +13 -13
  7. data/bin/load_shopify.rb +3 -1
  8. data/bin/shopify +2 -0
  9. data/docs/Gemfile.lock +23 -13
  10. data/docs/getting-started/index.md +3 -2
  11. data/docs/getting-started/install/index.md +55 -9
  12. data/docs/getting-started/uninstall/index.md +1 -1
  13. data/docs/getting-started/upgrade/index.md +8 -4
  14. data/ext/shopify-cli/extconf.rb +40 -20
  15. data/lib/project_types/extension/models/type.rb +1 -0
  16. data/lib/project_types/extension/tasks/create_extension.rb +1 -1
  17. data/lib/project_types/extension/tasks/get_app.rb +1 -1
  18. data/lib/project_types/extension/tasks/update_draft.rb +1 -1
  19. data/lib/project_types/node/commands/create.rb +4 -4
  20. data/lib/project_types/node/commands/deploy/heroku.rb +6 -1
  21. data/lib/project_types/node/commands/generate/billing.rb +7 -5
  22. data/lib/project_types/node/commands/generate/page.rb +9 -5
  23. data/lib/project_types/node/commands/generate/webhook.rb +5 -1
  24. data/lib/project_types/node/commands/serve.rb +5 -5
  25. data/lib/project_types/node/messages/messages.rb +5 -1
  26. data/lib/project_types/rails/commands/create.rb +56 -5
  27. data/lib/project_types/rails/commands/generate.rb +1 -0
  28. data/lib/project_types/rails/commands/generate/webhook.rb +3 -2
  29. data/lib/project_types/rails/commands/serve.rb +11 -7
  30. data/lib/project_types/rails/gem.rb +61 -6
  31. data/lib/project_types/rails/messages/messages.rb +32 -12
  32. data/lib/project_types/script/commands/create.rb +1 -5
  33. data/lib/project_types/script/commands/disable.rb +1 -2
  34. data/lib/project_types/script/commands/enable.rb +5 -5
  35. data/lib/project_types/script/commands/push.rb +1 -6
  36. data/lib/project_types/script/config/extension_points.yml +4 -4
  37. data/lib/project_types/script/errors.rb +8 -0
  38. data/lib/project_types/script/forms/create.rb +1 -1
  39. data/lib/project_types/script/layers/domain/errors.rb +2 -0
  40. data/lib/project_types/script/layers/infrastructure/errors.rb +1 -0
  41. data/lib/project_types/script/layers/infrastructure/script_service.rb +6 -2
  42. data/lib/project_types/script/messages/messages.rb +19 -48
  43. data/lib/project_types/script/ui/error_handler.rb +4 -0
  44. data/lib/rubygems_plugin.rb +18 -10
  45. data/lib/shopify-cli/admin_api/populate_resource_command.rb +1 -1
  46. data/lib/shopify-cli/command.rb +12 -6
  47. data/lib/shopify-cli/commands/connect.rb +7 -75
  48. data/lib/shopify-cli/commands/create.rb +1 -1
  49. data/lib/shopify-cli/commands/system.rb +21 -12
  50. data/lib/shopify-cli/context.rb +68 -0
  51. data/lib/shopify-cli/core/entry_point.rb +4 -1
  52. data/lib/shopify-cli/core/executor.rb +3 -5
  53. data/lib/shopify-cli/core/monorail.rb +1 -1
  54. data/lib/shopify-cli/db.rb +1 -1
  55. data/lib/shopify-cli/git.rb +1 -1
  56. data/lib/shopify-cli/heroku.rb +21 -5
  57. data/lib/shopify-cli/js_deps.rb +2 -2
  58. data/lib/shopify-cli/js_system.rb +2 -2
  59. data/lib/shopify-cli/messages/messages.rb +27 -20
  60. data/lib/shopify-cli/process_supervision.rb +60 -21
  61. data/lib/shopify-cli/project.rb +14 -6
  62. data/lib/shopify-cli/project_type.rb +3 -2
  63. data/lib/shopify-cli/sub_command.rb +1 -0
  64. data/lib/shopify-cli/task.rb +2 -2
  65. data/lib/shopify-cli/tasks.rb +11 -4
  66. data/lib/shopify-cli/tasks/ensure_env.rb +74 -17
  67. data/lib/shopify-cli/tunnel.rb +22 -7
  68. data/lib/shopify-cli/version.rb +1 -1
  69. data/lib/shopify_cli.rb +35 -9
  70. data/shopify-cli.gemspec +4 -1
  71. data/vendor/deps/cli-kit/REVISION +1 -1
  72. data/vendor/deps/cli-kit/lib/cli/kit.rb +1 -1
  73. data/vendor/deps/cli-kit/lib/cli/kit/autocall.rb +2 -2
  74. data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +12 -6
  75. data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +9 -11
  76. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +8 -2
  77. data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +7 -7
  78. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +48 -17
  79. data/vendor/deps/cli-ui/REVISION +1 -1
  80. data/vendor/deps/cli-ui/lib/cli/ui.rb +5 -4
  81. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +9 -3
  82. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +1 -0
  83. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -2
  84. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -0
  85. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +13 -5
  86. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +29 -2
  87. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +21 -10
  88. data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
  89. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +11 -2
  90. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +1 -0
  91. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -3
  92. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +6 -8
  93. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +2 -0
  94. data/vendor/gen/lib/gen.rb +39 -0
  95. data/vendor/gen/lib/gen/commands.rb +18 -0
  96. data/vendor/gen/lib/gen/commands/help.rb +20 -0
  97. data/vendor/gen/lib/gen/commands/new.rb +21 -0
  98. data/vendor/gen/lib/gen/entry_point.rb +10 -0
  99. data/vendor/gen/lib/gen/generator.rb +165 -0
  100. data/vendor/gen/template/.gitignore +2 -0
  101. data/vendor/gen/template/Gemfile +10 -0
  102. data/vendor/gen/template/README.md +1 -0
  103. data/vendor/gen/template/bin/testunit +23 -0
  104. data/vendor/gen/template/bin/update-deps +97 -0
  105. data/vendor/gen/template/dev-gems.yml +3 -0
  106. data/vendor/gen/template/dev-vendor.yml +4 -0
  107. data/vendor/gen/template/exe/__app__-gems +17 -0
  108. data/vendor/gen/template/exe/__app__-vendor +18 -0
  109. data/vendor/gen/template/lib/__app__.rb +33 -0
  110. data/vendor/gen/template/lib/__app__/commands.rb +18 -0
  111. data/vendor/gen/template/lib/__app__/commands/example.rb +19 -0
  112. data/vendor/gen/template/lib/__app__/commands/help.rb +21 -0
  113. data/vendor/gen/template/lib/__app__/entry_point.rb +10 -0
  114. data/vendor/gen/template/test/example_test.rb +17 -0
  115. data/vendor/gen/template/test/test_helper.rb +22 -0
  116. metadata +25 -4
  117. data/Vagrantfile +0 -17
  118. data/lib/project_types/script/forms/script_form.rb +0 -69
@@ -34,12 +34,8 @@ module Script
34
34
  end
35
35
 
36
36
  def self.help
37
- ShopifyCli::Context.message('script.create.help', ShopifyCli::TOOL_NAME)
38
- end
39
-
40
- def self.extended_help
41
37
  allowed_values = Script::Layers::Application::ExtensionPoints.types.map { |type| "{{cyan:#{type}}}" }
42
- ShopifyCli::Context.message('script.create.extended_help', ShopifyCli::TOOL_NAME, allowed_values.join(', '))
38
+ ShopifyCli::Context.message('script.create.help', ShopifyCli::TOOL_NAME, allowed_values.join(', '))
43
39
  end
44
40
  end
45
41
  end
@@ -3,9 +3,8 @@
3
3
  module Script
4
4
  module Commands
5
5
  class Disable < ShopifyCli::Command
6
- prerequisite_task :ensure_env
7
-
8
6
  def call(_args, _name)
7
+ ShopifyCli::Tasks::EnsureEnv.call(@ctx, required: [:api_key, :secret, :shop])
9
8
  project = ScriptProject.current
10
9
  Layers::Application::DisableScript.call(
11
10
  ctx: @ctx,
@@ -3,7 +3,6 @@
3
3
  module Script
4
4
  module Commands
5
5
  class Enable < ShopifyCli::Command
6
- prerequisite_task :ensure_env
7
6
  options do |parser, flags|
8
7
  parser.on('--config_props=KEYVALUEPAIRS', Array) do |t|
9
8
  flags[:config_props] = Hash[t.map { |s| s.split(':') }]
@@ -12,6 +11,7 @@ module Script
12
11
  end
13
12
 
14
13
  def call(_args, _name)
14
+ ShopifyCli::Tasks::EnsureEnv.call(@ctx, required: [:api_key, :secret, :shop])
15
15
  project = ScriptProject.current
16
16
  api_key = project.env[:api_key]
17
17
  shop_domain = project.env[:shop]
@@ -32,6 +32,8 @@ module Script
32
32
  title: project.script_name
33
33
  ))
34
34
  @ctx.puts(@ctx.message('script.enable.info'))
35
+ rescue Errors::InvalidConfigYAMLError => e
36
+ UI::ErrorHandler.pretty_print_and_raise(e)
35
37
  rescue StandardError => e
36
38
  UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.enable.error.operation_failed'))
37
39
  end
@@ -40,10 +42,6 @@ module Script
40
42
  ShopifyCli::Context.message('script.enable.help', ShopifyCli::TOOL_NAME)
41
43
  end
42
44
 
43
- def self.extended_help
44
- ShopifyCli::Context.message('script.enable.extended_help', ShopifyCli::TOOL_NAME)
45
- end
46
-
47
45
  private
48
46
 
49
47
  def acquire_configuration(config_file: nil, config_props: nil)
@@ -59,6 +57,8 @@ module Script
59
57
  })
60
58
  end
61
59
  configuration
60
+ rescue Errno::ENOENT, Psych::SyntaxError
61
+ raise Errors::InvalidConfigYAMLError, options.flags[:config_file]
62
62
  end
63
63
 
64
64
  # No slice pre Ruby 2.5 so roll our own
@@ -3,13 +3,12 @@
3
3
  module Script
4
4
  module Commands
5
5
  class Push < ShopifyCli::Command
6
- prerequisite_task :ensure_env
7
-
8
6
  options do |parser, flags|
9
7
  parser.on('--force') { |t| flags[:force] = t }
10
8
  end
11
9
 
12
10
  def call(_args, _name)
11
+ ShopifyCli::Tasks::EnsureEnv.call(@ctx, required: [:api_key, :secret, :shop])
13
12
  project = ScriptProject.current
14
13
  api_key = project.env[:api_key]
15
14
  return @ctx.puts(self.class.help) unless api_key &&
@@ -31,10 +30,6 @@ module Script
31
30
  def self.help
32
31
  ShopifyCli::Context.message('script.push.help', ShopifyCli::TOOL_NAME)
33
32
  end
34
-
35
- def self.extended_help
36
- ShopifyCli::Context.message('script.push.extended_help', ShopifyCli::TOOL_NAME)
37
- end
38
33
  end
39
34
  end
40
35
  end
@@ -1,24 +1,24 @@
1
1
  discount:
2
2
  assemblyscript:
3
3
  package: "@shopify/extension-point-as-discount"
4
- version: "^0.2.4"
4
+ version: "^0.2.10"
5
5
  sdk-version: "^6.0.0"
6
6
  toolchain-version: "^1.1.0"
7
7
  unit_limit_per_order:
8
8
  assemblyscript:
9
9
  package: "@shopify/extension-point-as-unit-limit-per-order"
10
- version: "^0.1.6"
10
+ version: "^0.1.12"
11
11
  sdk-version: "^6.0.0"
12
12
  toolchain-version: "^1.1.0"
13
13
  payment_filter:
14
14
  assemblyscript:
15
15
  package: "@shopify/extension-point-as-payment-filter"
16
- version: "^0.2.2"
16
+ version: "^0.2.8"
17
17
  sdk-version: "^6.0.0"
18
18
  toolchain-version: "^1.1.0"
19
19
  shipping_filter:
20
20
  assemblyscript:
21
21
  package: "@shopify/extension-point-as-shipping-filter"
22
- version: "^0.2.4"
22
+ version: "^0.2.10"
23
23
  sdk-version: "^6.0.0"
24
24
  toolchain-version: "^1.1.0"
@@ -9,9 +9,17 @@ module Script
9
9
  class NoExistingStoresError < ScriptProjectError
10
10
  attr_reader :organization_id
11
11
  def initialize(organization_id)
12
+ super()
12
13
  @organization_id = organization_id
13
14
  end
14
15
  end
15
16
  class ScriptProjectAlreadyExistsError < ScriptProjectError; end
17
+ class InvalidConfigYAMLError < ScriptProjectError
18
+ attr_reader :config_file
19
+ def initialize(config_file)
20
+ super()
21
+ @config_file = config_file
22
+ end
23
+ end
16
24
  end
17
25
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Script
4
4
  module Forms
5
- class Create < ScriptForm
5
+ class Create < ShopifyCli::Form
6
6
  flag_arguments :extension_point, :name
7
7
 
8
8
  def ask
@@ -8,12 +8,14 @@ module Script
8
8
  class InvalidExtensionPointError < ScriptProjectError
9
9
  attr_reader :type
10
10
  def initialize(type)
11
+ super()
11
12
  @type = type
12
13
  end
13
14
  end
14
15
  class ScriptNotFoundError < ScriptProjectError
15
16
  attr_reader :script_name, :extension_point_type
16
17
  def initialize(extension_point_type, script_name)
18
+ super()
17
19
  @script_name = script_name
18
20
  @extension_point_type = extension_point_type
19
21
  end
@@ -21,6 +21,7 @@ module Script
21
21
  class ScriptRepushError < ScriptProjectError
22
22
  attr_reader :api_key
23
23
  def initialize(api_key)
24
+ super()
24
25
  @api_key = api_key
25
26
  end
26
27
  end
@@ -49,7 +49,7 @@ module Script
49
49
  resp_hash = script_service_request(
50
50
  query_name: query_name,
51
51
  api_key: api_key,
52
- shop_domain: shop_domain,
52
+ shop_domain: format_shop_domain(shop_domain),
53
53
  variables: variables,
54
54
  )
55
55
  user_errors = resp_hash["data"]["shopScriptUpdateOrCreate"]["userErrors"]
@@ -76,7 +76,7 @@ module Script
76
76
  resp_hash = script_service_request(
77
77
  query_name: query_name,
78
78
  api_key: api_key,
79
- shop_domain: shop_domain,
79
+ shop_domain: format_shop_domain(shop_domain),
80
80
  variables: variables,
81
81
  )
82
82
  user_errors = resp_hash["data"]["shopScriptDelete"]["userErrors"]
@@ -91,6 +91,10 @@ module Script
91
91
 
92
92
  private
93
93
 
94
+ def format_shop_domain(shop_domain)
95
+ shop_domain.delete_suffix("/")
96
+ end
97
+
94
98
  class ScriptServiceAPI < ShopifyCli::API
95
99
  property(:api_key, accepts: String)
96
100
  property(:shop_id, accepts: Integer)
@@ -29,7 +29,7 @@ module Script
29
29
  no_existing_orgs_cause: "You don't have any partner organizations.",
30
30
  no_existing_orgs_help: "Please visit https://partners.shopify.com/ to create a partners account.",
31
31
 
32
- no_existing_stores_cause: "You don't have any development stores.",
32
+ no_existing_stores_cause: "You don't have any stores.",
33
33
  no_existing_stores_help: "Visit https://partners.shopify.com/%{organization_id}/stores/ to create one.",
34
34
 
35
35
  project_exists_cause: "Directory with the same name as the script already exists.",
@@ -38,9 +38,12 @@ module Script
38
38
  invalid_extension_cause: "Invalid extension point %s",
39
39
  invalid_extension_help: "Allowed values: %s.",
40
40
 
41
+ invalid_config: "Can't change the configuration values because %1$s is missing or "\
42
+ "it is not formatted properly.",
43
+
41
44
  script_not_found_cause: "Couldn't find script %s for extension point %s",
42
45
 
43
- app_not_installed_cause: "App not installed on development store.",
46
+ app_not_installed_cause: "App not installed on store.",
44
47
 
45
48
  app_script_not_pushed_help: "Push the script and then try this command again.",
46
49
 
@@ -67,18 +70,16 @@ module Script
67
70
  "on this extension point.",
68
71
  shop_script_conflict_help: "Disable that script or uninstall that app and try again.",
69
72
 
70
- shop_script_undefined_cause: "Script is already turned off in development store.",
73
+ shop_script_undefined_cause: "Script is already turned off in store.",
71
74
  },
72
75
 
73
76
  create: {
74
77
  help: <<~HELP,
75
78
  {{command:%1$s create script}}: Creates a script project.
76
79
  Usage: {{command:%1$s create script}}
77
- HELP
78
- extended_help: <<~HELP,
79
- \s\sOptions:
80
- \s\s{{command:--name=NAME}} Script project name. Use any string.
81
- \s\s{{command:--extension_point=TYPE}} Extension point name. Allowed values: %2$s.
80
+ Options:
81
+ {{command:--name=NAME}} Script project name. Use any string.
82
+ {{command:--extension_point=TYPE}} Extension point name. Allowed values: %2$s.
82
83
  HELP
83
84
 
84
85
  error: {
@@ -94,14 +95,12 @@ module Script
94
95
  help: <<~HELP,
95
96
  Build the script and put it into production. If you've already pushed a script with the same extension point, use --force to replace the current script with the newest one.
96
97
  Usage: {{command:%s push}}
97
- HELP
98
- extended_help: <<~HELP,
99
- \s\sOptions:
100
- \s\s{{command:[--force]}} Forces the script to be overwritten if an instance of it already exists.
98
+ Options:
99
+ {{command:[--force]}} Forces the script to be overwritten if an instance of it already exists.
101
100
  HELP
102
101
 
103
102
  error: {
104
- operation_failed: "Script not pushed.",
103
+ operation_failed: "Couldn't push script to app.",
105
104
  },
106
105
 
107
106
  script_pushed: "{{v}} Script pushed to app (API key: %{api_key}).",
@@ -109,27 +108,24 @@ module Script
109
108
 
110
109
  disable: {
111
110
  help: <<~HELP,
112
- Turn off script in development store.
111
+ Turn off script in store.
113
112
  Usage: {{command:%s disable}}
114
113
  HELP
115
114
 
116
115
  error: {
117
116
  operation_failed: "Can't disable script.",
118
- not_pushed_to_app: "Can't disable the script because it hasn't been pushed to the app.",
119
117
  },
120
118
 
121
- script_disabled: "{{v}} Script disabled. Script is turned off in development store.",
119
+ script_disabled: "{{v}} Script disabled. Script is turned off in store.",
122
120
  },
123
121
 
124
122
  enable: {
125
123
  help: <<~HELP,
126
- Turn on script in development store.
124
+ Turn on script in store.
127
125
  Usage: {{command:%s enable}}
128
- HELP
129
- extended_help: <<~HELP,
130
- \s\sOptions:
131
- \s\s{{command:--config_props='name1:value1, name2:value2'}} Optional. Define the configuration of your script by passing individual name and value pairs. If used with --config_file, then matching values in --config_props will override those set in the file.
132
- \s\s{{command:--config_file=<path/to/YAMLFilename>}} Optional. Define the configuration of your script using a YAML formatted file. --config_props values override properties in this file.
126
+ Options:
127
+ {{command:--config_props='name1:value1, name2:value2'}} Optional. Define the configuration of your script by passing individual name and value pairs. If used with --config_file, then matching values in --config_props will override those set in the file.
128
+ {{command:--config_file=<path/to/YAMLFilename>}} Optional. Define the configuration of your script using a YAML formatted file. --config_props values override properties in this file.
133
129
  HELP
134
130
 
135
131
  info: "{{*}} A script always remains enabled until you disable it - even after pushing "\
@@ -138,11 +134,10 @@ module Script
138
134
 
139
135
  error: {
140
136
  operation_failed: "Can't enable script.",
141
- not_pushed_to_app: "Can't enable the script because it hasn't been pushed to the app.",
142
137
  },
143
138
 
144
139
  script_enabled: "{{v}} Script enabled. %{type} script %{title} in app (API key: %{api_key}) "\
145
- "is turned on in development store {{green:%{shop_domain}}}",
140
+ "is turned on in store {{green:%{shop_domain}}}",
146
141
  },
147
142
 
148
143
  project_deps: {
@@ -152,35 +147,11 @@ module Script
152
147
  installed: "Missing dependencies installed",
153
148
  },
154
149
 
155
- test: {
156
- help: <<~HELP,
157
- Runs unit tests on your script.
158
- Usage: {{command:%s test}}
159
- HELP
160
-
161
- error: {
162
- operation_failed: "Tests didn't run or they ran with failures.",
163
- },
164
-
165
- running: "Running tests",
166
- success: "{{v}} Tests finished.",
167
- },
168
-
169
150
  forms: {
170
151
  create: {
171
152
  select_extension_point: "Which extension point do you want to use?",
172
153
  script_name: "Script Name",
173
154
  },
174
- script_form: {
175
- ask_app_api_key_default: "Which app do you want this script to belong to?",
176
- ask_shop_domain_default: "Select a development store",
177
- fetching_organizations: "Fetching partner organizations",
178
- fetched_organizations: "Fetched partner organizations",
179
- select_organization: "Select partner organization.",
180
- using_app: "Using app {{green:%{title} (%{api_key})}}.",
181
- using_development_store: "Using development store {{green:%{domain}}}",
182
- using_organization: "Partner organization {{green:%s}}.",
183
- },
184
155
  },
185
156
 
186
157
  application: {
@@ -44,6 +44,10 @@ module Script
44
44
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_context_cause'),
45
45
  help_suggestion: ShopifyCli::Context.message('script.error.invalid_context_help'),
46
46
  }
47
+ when Errors::InvalidConfigYAMLError
48
+ {
49
+ cause_of_error: ShopifyCli::Context.message('script.error.invalid_config', e.config_file),
50
+ }
47
51
  when Errors::InvalidScriptNameError
48
52
  {
49
53
  cause_of_error: ShopifyCli::Context.message('script.error.invalid_script_name_cause'),
@@ -1,17 +1,25 @@
1
1
  Gem.post_uninstall do |uninstaller|
2
2
  if uninstaller.spec.name == 'shopify-cli'
3
- require 'fileutils'
3
+ if RUBY_PLATFORM.match(/mingw32/)
4
+ bat_path = File.dirname(RbConfig.ruby)
5
+ bat = "#{bat_path}\\shopify.bat"
4
6
 
5
- symlink = '/usr/local/bin/shopify'
7
+ # delete the auto-generated batch script
8
+ File.unlink(bat)
9
+ else
10
+ require 'fileutils'
6
11
 
7
- # delete the symbolic link IFF it exists AND it does not point to a file
8
- # (i.e., it's been left hanging as a result of the uninstall, as expected)
9
- #
10
- # if the file still exists, either the uninstall failed (possible but
11
- # unlikely) OR
12
- # there's another installation of the gem in another ruby folder that has
13
- # overwritten it, so leave the symbolic link alone
14
- system("sudo rm -f #{symlink}") if File.symlink?(symlink) && !File.exist?(symlink)
12
+ symlink = '/usr/local/bin/shopify'
13
+
14
+ # delete the symbolic link IFF it exists AND it does not point to a file
15
+ # (i.e., it's been left hanging as a result of the uninstall, as expected)
16
+ #
17
+ # if the file still exists, either the uninstall failed (possible but
18
+ # unlikely) OR
19
+ # there's another installation of the gem in another ruby folder that has
20
+ # overwritten it, so leave the symbolic link alone
21
+ system("sudo rm -f #{symlink}") if File.symlink?(symlink) && !File.exist?(symlink)
22
+ end
15
23
  end
16
24
 
17
25
  true
@@ -118,7 +118,7 @@ module ShopifyCli
118
118
  kwargs = { input: data }
119
119
  kwargs[:shop] = @shop
120
120
  resp = AdminAPI.query(
121
- @ctx, "create_#{snake_case_resource_type}", kwargs
121
+ @ctx, "create_#{snake_case_resource_type}", **kwargs
122
122
  )
123
123
  @ctx.abort(resp['errors']) if resp['errors']
124
124
  @ctx.done(message(resp['data'])) unless @silent
@@ -9,17 +9,19 @@ module ShopifyCli
9
9
  attr_accessor :options
10
10
 
11
11
  class << self
12
- attr_writer :ctx
12
+ attr_writer :ctx, :task_registry
13
13
 
14
14
  def call(args, command_name)
15
15
  subcommand, resolved_name = subcommand_registry.lookup_command(args.first)
16
16
  if subcommand
17
17
  subcommand.ctx = @ctx
18
+ subcommand.task_registry = @task_registry
18
19
  subcommand.call(args, resolved_name, command_name)
19
20
  else
20
21
  cmd = new(@ctx)
21
22
  cmd.options.parse(@_options, args)
22
23
  return call_help(command_name) if cmd.options.help
24
+ run_prerequisites
23
25
  cmd.call(args, command_name)
24
26
  end
25
27
  end
@@ -41,13 +43,16 @@ module ShopifyCli
41
43
  end
42
44
 
43
45
  def prerequisite_task(*tasks)
44
- tasks.each do |task|
45
- prerequisite_tasks[task] = ShopifyCli::Tasks::Registry[task]
46
- end
46
+ @prerequisite_tasks ||= []
47
+ @prerequisite_tasks += tasks
48
+ end
49
+
50
+ def run_prerequisites
51
+ (@prerequisite_tasks || []).each { |task| task_registry[task]&.call(@ctx) }
47
52
  end
48
53
 
49
- def prerequisite_tasks
50
- @prerequisite_tasks ||= {}
54
+ def task_registry
55
+ @task_registry || ShopifyCli::Tasks::Registry
51
56
  end
52
57
 
53
58
  def call_help(*cmds)
@@ -57,6 +62,7 @@ module ShopifyCli
57
62
  end
58
63
 
59
64
  def initialize(ctx = nil)
65
+ super()
60
66
  @ctx = ctx || ShopifyCli::Context.new
61
67
  self.options = Options.new
62
68
  end