shopify-cli 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/CHANGELOG.md +20 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +13 -13
  6. data/bin/load_shopify.rb +3 -1
  7. data/bin/shopify +2 -0
  8. data/docs/Gemfile.lock +23 -13
  9. data/docs/getting-started/install/index.md +37 -1
  10. data/docs/getting-started/migrate/index.md +34 -1
  11. data/ext/shopify-cli/extconf.rb +40 -20
  12. data/lib/project_types/extension/cli.rb +1 -1
  13. data/lib/project_types/extension/commands/build.rb +1 -1
  14. data/lib/project_types/extension/models/type.rb +1 -0
  15. data/lib/project_types/extension/tasks/create_extension.rb +1 -1
  16. data/lib/project_types/extension/tasks/get_app.rb +1 -1
  17. data/lib/project_types/extension/tasks/update_draft.rb +1 -1
  18. data/lib/project_types/node/commands/create.rb +4 -4
  19. data/lib/project_types/node/commands/deploy/heroku.rb +6 -1
  20. data/lib/project_types/node/commands/generate/billing.rb +6 -5
  21. data/lib/project_types/node/commands/generate/page.rb +8 -5
  22. data/lib/project_types/node/commands/generate/webhook.rb +4 -1
  23. data/lib/project_types/node/messages/messages.rb +3 -2
  24. data/lib/project_types/rails/cli.rb +0 -1
  25. data/lib/project_types/rails/commands/create.rb +52 -4
  26. data/lib/project_types/rails/commands/generate.rb +1 -0
  27. data/lib/project_types/rails/commands/generate/webhook.rb +3 -2
  28. data/lib/project_types/rails/commands/serve.rb +6 -2
  29. data/lib/project_types/rails/gem.rb +61 -6
  30. data/lib/project_types/rails/messages/messages.rb +29 -13
  31. data/lib/project_types/script/cli.rb +2 -3
  32. data/lib/project_types/script/commands/create.rb +5 -9
  33. data/lib/project_types/script/commands/disable.rb +4 -15
  34. data/lib/project_types/script/commands/enable.rb +37 -13
  35. data/lib/project_types/script/commands/push.rb +8 -13
  36. data/lib/project_types/script/config/extension_points.yml +9 -3
  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/application/create_script.rb +7 -6
  40. data/lib/project_types/script/layers/application/disable_script.rb +9 -7
  41. data/lib/project_types/script/layers/application/enable_script.rb +11 -9
  42. data/lib/project_types/script/layers/application/push_script.rb +6 -4
  43. data/lib/project_types/script/layers/domain/errors.rb +2 -0
  44. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +2 -2
  45. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +2 -2
  46. data/lib/project_types/script/layers/infrastructure/errors.rb +2 -0
  47. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +1 -1
  48. data/lib/project_types/script/layers/infrastructure/script_repository.rb +1 -1
  49. data/lib/project_types/script/layers/infrastructure/script_service.rb +2 -0
  50. data/lib/project_types/script/messages/messages.rb +25 -31
  51. data/lib/project_types/script/script_project.rb +8 -4
  52. data/lib/project_types/script/templates/ts/as-pect.config.js +6 -0
  53. data/lib/project_types/script/ui/error_handler.rb +8 -0
  54. data/lib/project_types/script/ui/printing_spinner.rb +75 -0
  55. data/lib/rubygems_plugin.rb +18 -10
  56. data/lib/shopify-cli/admin_api/populate_resource_command.rb +1 -1
  57. data/lib/shopify-cli/admin_api/schema.rb +20 -8
  58. data/lib/shopify-cli/command.rb +14 -11
  59. data/lib/shopify-cli/commands.rb +1 -0
  60. data/lib/shopify-cli/commands/config.rb +44 -0
  61. data/lib/shopify-cli/commands/connect.rb +8 -69
  62. data/lib/shopify-cli/commands/create.rb +2 -2
  63. data/lib/shopify-cli/commands/help.rb +1 -1
  64. data/lib/shopify-cli/commands/system.rb +22 -13
  65. data/lib/shopify-cli/context.rb +38 -1
  66. data/lib/shopify-cli/core.rb +0 -1
  67. data/lib/shopify-cli/core/entry_point.rb +1 -1
  68. data/lib/shopify-cli/core/executor.rb +3 -5
  69. data/lib/shopify-cli/core/monorail.rb +1 -1
  70. data/lib/shopify-cli/db.rb +1 -1
  71. data/lib/shopify-cli/feature.rb +97 -0
  72. data/lib/shopify-cli/heroku.rb +21 -5
  73. data/lib/shopify-cli/js_deps.rb +2 -2
  74. data/lib/shopify-cli/js_system.rb +2 -2
  75. data/lib/shopify-cli/messages/messages.rb +37 -12
  76. data/lib/shopify-cli/partners_api/organizations.rb +7 -7
  77. data/lib/shopify-cli/process_supervision.rb +60 -21
  78. data/lib/shopify-cli/project.rb +14 -6
  79. data/lib/shopify-cli/project_type.rb +5 -7
  80. data/lib/shopify-cli/sub_command.rb +1 -0
  81. data/lib/shopify-cli/task.rb +2 -2
  82. data/lib/shopify-cli/tasks.rb +11 -4
  83. data/lib/shopify-cli/tasks/ensure_env.rb +72 -16
  84. data/lib/shopify-cli/tasks/update_dashboard_urls.rb +4 -3
  85. data/lib/shopify-cli/tunnel.rb +44 -14
  86. data/lib/shopify-cli/version.rb +1 -1
  87. data/lib/shopify_cli.rb +36 -9
  88. data/shopify-cli.gemspec +4 -1
  89. data/vendor/deps/cli-kit/REVISION +1 -1
  90. data/vendor/deps/cli-kit/lib/cli/kit.rb +1 -1
  91. data/vendor/deps/cli-kit/lib/cli/kit/autocall.rb +2 -2
  92. data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +12 -6
  93. data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +9 -11
  94. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +8 -2
  95. data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +7 -7
  96. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +48 -17
  97. data/vendor/deps/cli-ui/REVISION +1 -1
  98. data/vendor/deps/cli-ui/lib/cli/ui.rb +5 -4
  99. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +9 -3
  100. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +1 -0
  101. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -2
  102. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -0
  103. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +13 -5
  104. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +29 -2
  105. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +21 -10
  106. data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
  107. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +11 -2
  108. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +1 -0
  109. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -3
  110. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +6 -8
  111. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +2 -0
  112. data/vendor/gen/lib/gen.rb +39 -0
  113. data/vendor/gen/lib/gen/commands.rb +18 -0
  114. data/vendor/gen/lib/gen/commands/help.rb +20 -0
  115. data/vendor/gen/lib/gen/commands/new.rb +21 -0
  116. data/vendor/gen/lib/gen/entry_point.rb +10 -0
  117. data/vendor/gen/lib/gen/generator.rb +165 -0
  118. data/vendor/gen/template/.gitignore +2 -0
  119. data/vendor/gen/template/Gemfile +10 -0
  120. data/vendor/gen/template/README.md +1 -0
  121. data/vendor/gen/template/bin/testunit +23 -0
  122. data/vendor/gen/template/bin/update-deps +97 -0
  123. data/vendor/gen/template/dev-gems.yml +3 -0
  124. data/vendor/gen/template/dev-vendor.yml +4 -0
  125. data/vendor/gen/template/exe/__app__-gems +17 -0
  126. data/vendor/gen/template/exe/__app__-vendor +18 -0
  127. data/vendor/gen/template/lib/__app__.rb +33 -0
  128. data/vendor/gen/template/lib/__app__/commands.rb +18 -0
  129. data/vendor/gen/template/lib/__app__/commands/example.rb +19 -0
  130. data/vendor/gen/template/lib/__app__/commands/help.rb +21 -0
  131. data/vendor/gen/template/lib/__app__/entry_point.rb +10 -0
  132. data/vendor/gen/template/test/example_test.rb +17 -0
  133. data/vendor/gen/template/test/test_helper.rb +22 -0
  134. metadata +28 -6
  135. data/Vagrantfile +0 -17
  136. data/lib/project_types/script/forms/enable.rb +0 -24
  137. data/lib/project_types/script/forms/push.rb +0 -19
  138. data/lib/project_types/script/forms/script_form.rb +0 -66
@@ -18,6 +18,7 @@ module ShopifyCli
18
18
  @core_commands.include?(cmd)
19
19
  end
20
20
 
21
+ register :Config, 'config', 'shopify-cli/commands/config', true
21
22
  register :Connect, 'connect', 'shopify-cli/commands/connect', true
22
23
  register :Create, 'create', 'shopify-cli/commands/create', true
23
24
  register :Help, 'help', 'shopify-cli/commands/help', true
@@ -0,0 +1,44 @@
1
+ require 'shopify_cli'
2
+
3
+ module ShopifyCli
4
+ module Commands
5
+ class Config < ShopifyCli::Command
6
+ hidden_feature(feature_set: :debug)
7
+
8
+ subcommand :Feature, 'feature'
9
+
10
+ def call(*)
11
+ @ctx.puts(self.class.help)
12
+ end
13
+
14
+ def self.help
15
+ ShopifyCli::Context.message('core.config.help', ShopifyCli::TOOL_NAME)
16
+ end
17
+
18
+ class Feature < ShopifyCli::SubCommand
19
+ options do |parser, flags|
20
+ parser.on('--enable') { flags[:action] = 'enable' }
21
+ parser.on('--disable') { flags[:action] = 'disable' }
22
+ parser.on('--status') { flags[:action] = 'status' }
23
+ end
24
+
25
+ def call(args, _name)
26
+ feature_name = args.shift
27
+ return @ctx.puts(@ctx.message('core.config.help', ShopifyCli::TOOL_NAME)) if feature_name.nil?
28
+ is_enabled = ShopifyCli::Feature.enabled?(feature_name)
29
+ if options.flags[:action] == 'disable' && is_enabled
30
+ ShopifyCli::Feature.disable(feature_name)
31
+ @ctx.puts(@ctx.message('core.config.feature.disabled', is_enabled))
32
+ elsif options.flags[:action] == 'enable' && !is_enabled
33
+ ShopifyCli::Feature.enable(feature_name)
34
+ @ctx.puts(@ctx.message('core.config.feature.enabled', feature_name))
35
+ elsif is_enabled
36
+ @ctx.puts(@ctx.message('core.config.feature.is_enabled', feature_name))
37
+ else
38
+ @ctx.puts(@ctx.message('core.config.feature.is_disabled', feature_name))
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -6,27 +6,20 @@ module ShopifyCli
6
6
  def call(*)
7
7
  project_type = ask_project_type unless Project.has_current?
8
8
 
9
- if Project.has_current? && Project.current
9
+ if Project.has_current? && Project.current && Project.current.env
10
10
  @ctx.puts @ctx.message('core.connect.already_connected_warning')
11
11
  prod_warning = @ctx.message('core.connect.production_warning')
12
12
  @ctx.puts prod_warning if [:rails, :node].include?(Project.current_project_type)
13
13
  end
14
14
 
15
- env_data = begin
16
- Resources::EnvFile.parse_external_env
17
- rescue Errno::ENOENT
18
- {}
19
- end
20
-
21
- org = fetch_org
22
- id = org['id']
23
- app = get_app(org['apps'])
24
- shop = get_shop(org['stores'], id)
25
-
26
- write_env(app, shop, env_data[:scopes], env_data[:extra])
27
- write_cli_yml(project_type, id) unless Project.has_current?
15
+ org = ShopifyCli::Tasks::EnsureEnv.call(@ctx, regenerate: true)
16
+ write_cli_yml(project_type, org['id']) unless Project.has_current?
17
+ api_key = Project.current(force_reload: true).env['api_key']
18
+ @ctx.puts(@ctx.message('core.connect.connected', get_app(org['apps'], api_key).first["title"]))
19
+ end
28
20
 
29
- @ctx.puts(@ctx.message('core.connect.connected', app.first['title']))
21
+ def get_app(apps, api_key)
22
+ apps.select { |app| app["apiKey"] == api_key }
30
23
  end
31
24
 
32
25
  def ask_project_type
@@ -37,60 +30,6 @@ module ShopifyCli
37
30
  end
38
31
  end
39
32
 
40
- def fetch_org
41
- orgs = PartnersAPI::Organizations.fetch_with_app(@ctx)
42
- org_id = if orgs.count == 1
43
- orgs.first["id"]
44
- else
45
- CLI::UI::Prompt.ask(@ctx.message('core.connect.organization_select')) do |handler|
46
- orgs.each do |org|
47
- handler.option(
48
- ctx.message('core.partners_api.org_name_and_id', org['businessName'], org['id'])
49
- ) { org["id"] }
50
- end
51
- end
52
- end
53
- org = orgs.find { |o| o["id"] == org_id }
54
- org
55
- end
56
-
57
- def get_app(apps)
58
- app_id = if apps.count == 1
59
- apps.first["id"]
60
- else
61
- CLI::UI::Prompt.ask(@ctx.message('core.connect.app_select')) do |handler|
62
- apps.each { |app| handler.option(app["title"]) { app["id"] } }
63
- end
64
- end
65
- apps.select { |app| app["id"] == app_id }
66
- end
67
-
68
- def get_shop(shops, id)
69
- if shops.count == 1
70
- shop = shops.first["shopDomain"]
71
- elsif shops.count == 0
72
- @ctx.puts(@ctx.message('core.connect.no_development_stores', id))
73
- else
74
- shop = CLI::UI::Prompt.ask(@ctx.message('core.connect.development_store_select')) do |handler|
75
- shops.each { |s| handler.option(s["shopName"]) { s["shopDomain"] } }
76
- end
77
- end
78
- shop
79
- end
80
-
81
- def write_env(app, shop, scopes, extra)
82
- scopes = 'write_products,write_customers,write_draft_orders' if scopes.nil?
83
- extra = {} if extra.nil?
84
-
85
- Resources::EnvFile.new(
86
- api_key: app.first["apiKey"],
87
- secret: app.first["apiSecretKeys"].first["secret"],
88
- shop: shop,
89
- scopes: scopes,
90
- extra: extra,
91
- ).write(@ctx)
92
- end
93
-
94
33
  def write_cli_yml(project_type, org_id)
95
34
  ShopifyCli::Project.write(
96
35
  @ctx,
@@ -28,11 +28,11 @@ module ShopifyCli
28
28
  def self.all_visible_type
29
29
  ProjectType
30
30
  .load_all
31
- .select { |type| !type.hidden }
31
+ .select { |type| !type.hidden? }
32
32
  end
33
33
 
34
34
  def self.help
35
- project_types = all_visible_type.map(&:project_type).join(" | ")
35
+ project_types = all_visible_type.map(&:project_type).sort.join(" | ")
36
36
  ShopifyCli::Context.message('core.create.help', ShopifyCli::TOOL_NAME, project_types)
37
37
  end
38
38
 
@@ -47,7 +47,7 @@ module ShopifyCli
47
47
 
48
48
  def core_commands
49
49
  resolved_commands
50
- .select { |_name, c| !c.hidden }
50
+ .select { |_name, c| !c.hidden? }
51
51
  .select { |name, _c| Commands.core_command?(name) }
52
52
  end
53
53
 
@@ -4,7 +4,7 @@ require 'rbconfig'
4
4
  module ShopifyCli
5
5
  module Commands
6
6
  class System < ShopifyCli::Command
7
- hidden_command
7
+ hidden_feature(feature_set: :debug)
8
8
 
9
9
  def call(args, _name)
10
10
  show_all_details = false
@@ -36,11 +36,13 @@ module ShopifyCli
36
36
  cli_constants_extra = %w(
37
37
  PROJECT_TYPES_DIR
38
38
  TEMP_DIR
39
- CACHE_DIR
40
- TOOL_CONFIG_PATH
41
- LOG_FILE
42
- DEBUG_LOG_FILE
43
39
  )
40
+ cli_path_methods = [
41
+ :cache_dir,
42
+ :tool_config_path,
43
+ :log_file,
44
+ :debug_log_file,
45
+ ]
44
46
 
45
47
  cli_constants += cli_constants_extra if show_all_details
46
48
 
@@ -48,6 +50,12 @@ module ShopifyCli
48
50
  cli_constants.each do |s|
49
51
  @ctx.puts(" " + @ctx.message('core.system.const', s, ShopifyCli.const_get(s.to_sym)) + "\n")
50
52
  end
53
+
54
+ if show_all_details
55
+ cli_path_methods.each do |m|
56
+ @ctx.puts(" " + @ctx.message('core.system.const', m.upcase, ShopifyCli.send(m)) + "\n")
57
+ end
58
+ end
51
59
  end
52
60
 
53
61
  def display_cli_ruby(_show_all_details)
@@ -60,13 +68,14 @@ module ShopifyCli
60
68
  end
61
69
 
62
70
  def display_utility_commands(_show_all_details)
63
- commands = %w(git curl tar unzip)
71
+ commands = %w(git curl tar)
64
72
 
65
73
  @ctx.puts("\n" + @ctx.message('core.system.command_header'))
66
74
  commands.each do |s|
67
- output, status = @ctx.capture2e('which', s)
68
- if status.success?
69
- @ctx.puts(" " + @ctx.message('core.system.command_with_path', s, output))
75
+ cmd_path = @ctx.which(s)
76
+
77
+ if !cmd_path.nil?
78
+ @ctx.puts(" " + @ctx.message('core.system.command_with_path', s, cmd_path))
70
79
  else
71
80
  @ctx.puts(" " + @ctx.message('core.system.command_not_found', s))
72
81
  end
@@ -74,7 +83,7 @@ module ShopifyCli
74
83
  end
75
84
 
76
85
  def display_ngrok
77
- ngrok_location = File.join(ShopifyCli::CACHE_DIR, 'ngrok')
86
+ ngrok_location = File.join(ShopifyCli.cache_dir, @ctx.windows? ? 'ngrok.exe' : 'ngrok')
78
87
  if File.exist?(ngrok_location)
79
88
  @ctx.puts(" " + @ctx.message('core.system.ngrok_available', ngrok_location))
80
89
  else
@@ -94,11 +103,11 @@ module ShopifyCli
94
103
  def display_project(project_type, commands)
95
104
  @ctx.puts("\n" + @ctx.message('core.system.project.header', project_type))
96
105
  commands.each do |s|
97
- output, status = @ctx.capture2e('which', s)
98
- if status.success?
106
+ cmd_path = @ctx.which(s)
107
+ if !cmd_path.nil?
99
108
  version_output, _ = @ctx.capture2e(s, '--version')
100
109
  version = version_output.match(/(\d+\.[^\s]+)/)[0]
101
- @ctx.puts(" " + @ctx.message('core.system.project.command_with_path', s, output.strip, version.strip))
110
+ @ctx.puts(" " + @ctx.message('core.system.project.command_with_path', s, cmd_path.strip, version.strip))
102
111
  else
103
112
  @ctx.puts(" " + @ctx.message('core.system.project.command_not_found', s))
104
113
  end
@@ -56,6 +56,7 @@ module ShopifyCli
56
56
  host = uname
57
57
  return :mac if /darwin/.match(host)
58
58
  return :linux if /linux/.match(host)
59
+ return :windows if /mingw32/.match(host)
59
60
  end
60
61
 
61
62
  # will return true if the cli is running on an apple computer.
@@ -68,6 +69,11 @@ module ShopifyCli
68
69
  os == :linux
69
70
  end
70
71
 
72
+ # will return true if the cli is running on Windows
73
+ def windows?
74
+ os == :windows
75
+ end
76
+
71
77
  # will return true if the cli is being run from an installation, and not a
72
78
  # development instance. The gem installation will not have a 'test' directory.
73
79
  # See `#development?` for checking for development environment.
@@ -146,10 +152,19 @@ module ShopifyCli
146
152
  # #### Parameters
147
153
  # * `path` - the file path to a directory, relative to the context root to remove from the FS
148
154
  #
149
- def exist?(path)
155
+ def dir_exist?(path)
150
156
  Dir.exist?(ctx_path(path))
151
157
  end
152
158
 
159
+ # checks if a file exists, the filepath is relative to the command root unless absolute
160
+ #
161
+ # #### Parameters
162
+ # * `path` - the file path to a file, relative to the context root to remove from the FS
163
+ #
164
+ def file_exist?(path)
165
+ File.exist?(ctx_path(path))
166
+ end
167
+
153
168
  # will recursively copy a directory from the FS, the filepath is relative to the command
154
169
  # root unless absolute
155
170
  #
@@ -409,6 +424,28 @@ module ShopifyCli
409
424
  end
410
425
  end
411
426
 
427
+ # Checks if the given command exists in the system
428
+ #
429
+ # #### Parameters
430
+ # - `cmd`: The command to test
431
+ #
432
+ # #### Returns
433
+ # The path of the executable if it is found
434
+ #
435
+ # @todo This is currently a duplicate of CLI::Kit::System.which() - we should make that method public when we make
436
+ # Kit changes and make this a wrapper instead.
437
+ def which(cmd)
438
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
439
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
440
+ exts.each do |ext|
441
+ exe = File.join(File.expand_path(path), "#{cmd}#{ext}")
442
+ return exe if File.executable?(exe) && !File.directory?(exe)
443
+ end
444
+ end
445
+
446
+ nil
447
+ end
448
+
412
449
  private
413
450
 
414
451
  def ctx_path(fname)
@@ -4,6 +4,5 @@ module ShopifyCli
4
4
  autoload :Executor, 'shopify-cli/core/executor'
5
5
  autoload :HelpResolver, 'shopify-cli/core/help_resolver'
6
6
  autoload :Monorail, 'shopify-cli/core/monorail'
7
- autoload :Update, 'shopify-cli/core/update'
8
7
  end
9
8
  end
@@ -35,7 +35,7 @@ module ShopifyCli
35
35
  task_registry = ShopifyCli::Tasks::Registry
36
36
 
37
37
  command, command_name, args = ShopifyCli::Resolver.call(args)
38
- executor = ShopifyCli::Core::Executor.new(ctx, task_registry, log_file: ShopifyCli::LOG_FILE)
38
+ executor = ShopifyCli::Core::Executor.new(ctx, task_registry, log_file: ShopifyCli.log_file)
39
39
  ShopifyCli::Core::Monorail.log(command_name, args) do
40
40
  executor.call(command, command_name, args)
41
41
  end
@@ -3,16 +3,14 @@ require 'shopify_cli'
3
3
  module ShopifyCli
4
4
  module Core
5
5
  class Executor < CLI::Kit::Executor
6
- def initialize(ctx, task_registry, *args)
6
+ def initialize(ctx, task_registry, *args, **kwargs)
7
7
  @ctx = ctx || ShopifyCli::Context.new
8
8
  @task_registry = task_registry || ShopifyCli::Tasks::TaskRegistry.new
9
- super(*args)
9
+ super(*args, **kwargs)
10
10
  end
11
11
 
12
12
  def call(command, command_name, args)
13
- command.prerequisite_tasks.each do |task, _|
14
- @task_registry[task]&.call(@ctx)
15
- end
13
+ command.task_registry = @task_registry
16
14
  command.ctx = @ctx
17
15
  super
18
16
  end
@@ -99,7 +99,7 @@ module ShopifyCli
99
99
  success: err.nil?,
100
100
  error_message: err,
101
101
  uname: RbConfig::CONFIG["host"],
102
- cli_version: ShopifyCli::Git.sha(dir: ShopifyCli::ROOT),
102
+ cli_version: ShopifyCli::VERSION,
103
103
  ruby_version: RUBY_VERSION,
104
104
  }.tap do |payload|
105
105
  payload[:metadata] = JSON.dump(metadata) unless metadata.empty?
@@ -14,7 +14,7 @@ module ShopifyCli
14
14
 
15
15
  attr_reader :db # :nodoc:
16
16
 
17
- def initialize(path: File.join(ShopifyCli::CACHE_DIR, ".db.pstore")) # :nodoc:
17
+ def initialize(path: File.join(ShopifyCli.cache_dir, ".db.pstore")) # :nodoc:
18
18
  @db = PStore.new(path)
19
19
  end
20
20
 
@@ -0,0 +1,97 @@
1
+ module ShopifyCli
2
+ ##
3
+ # ShopifyCli::Feature contains the logic to hide and show features across the CLI
4
+ # These features can be either commands or project types currently.
5
+ #
6
+ # Feature flags will persist between runs so if the flag is enabled or disabled,
7
+ # it will still be in that same state on the next cli invocation.
8
+ class Feature
9
+ SECTION = 'features'
10
+
11
+ ##
12
+ # ShopifyCli::Feature::Set is included on commands and projects to allow you to hide
13
+ # and enable projects and commands based on feature flags.
14
+ module Set
15
+ ##
16
+ # will hide a feature, either a project_type or a command
17
+ #
18
+ # #### Parameters
19
+ #
20
+ # * `feature_set` - either a single, or array of symbols that represent feature sets
21
+ #
22
+ # #### Example
23
+ #
24
+ # module ShopifyCli
25
+ # module Commands
26
+ # class Config < ShopifyCli::Command
27
+ # hidden_feature(feature_set: :basic)
28
+ # ....
29
+ #
30
+ def hidden_feature(feature_set: [])
31
+ @feature_hidden = true
32
+ @hidden_feature_set = Array(feature_set).compact
33
+ end
34
+
35
+ ##
36
+ # will return if the feature has been hidden or not
37
+ #
38
+ # #### Returns
39
+ #
40
+ # * `is_hidden` - returns true if the feature has been hidden and false otherwise
41
+ #
42
+ # #### Example
43
+ #
44
+ # ShopifyCli::Commands::Config.hidden?
45
+ #
46
+ def hidden?
47
+ enabled = (@hidden_feature_set || []).any? do |feature|
48
+ Feature.enabled?(feature)
49
+ end
50
+ @feature_hidden && !enabled
51
+ end
52
+ end
53
+
54
+ class << self
55
+ ##
56
+ # will enable a feature in the CLI.
57
+ #
58
+ # #### Parameters
59
+ #
60
+ # * `feature` - a symbol representing the flag to be enabled
61
+ def enable(feature)
62
+ set(feature, true)
63
+ end
64
+
65
+ ##
66
+ # will disable a feature in the CLI.
67
+ #
68
+ # #### Parameters
69
+ #
70
+ # * `feature` - a symbol representing the flag to be disabled
71
+ def disable(feature)
72
+ set(feature, false)
73
+ end
74
+
75
+ ##
76
+ # will check if the feature has been enabled
77
+ #
78
+ # #### Parameters
79
+ #
80
+ # * `feature` - a symbol representing a flag that the status should be requested
81
+ #
82
+ # #### Returns
83
+ #
84
+ # * `is_enabled` - will be true if the feature has been enabled.
85
+ def enabled?(feature)
86
+ return false if feature.nil?
87
+ ShopifyCli::Config.get_bool(SECTION, feature.to_s)
88
+ end
89
+
90
+ private
91
+
92
+ def set(feature, value)
93
+ ShopifyCli::Config.set(SECTION, feature.to_s, value)
94
+ end
95
+ end
96
+ end
97
+ end