Class: Script::Commands::Create

Inherits:
ShopifyCli::SubCommand show all
Defined in:
lib/project_types/script/commands/create.rb

Instance Attribute Summary

Attributes inherited from ShopifyCli::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShopifyCli::SubCommand

call

Methods inherited from ShopifyCli::Command

call, call_help, #initialize, options, prerequisite_task, run_prerequisites, subcommand, subcommand_registry

Methods included from ShopifyCli::Feature::Set

#hidden?, #hidden_feature

Constructor Details

This class inherits a constructor from ShopifyCli::Command

Class Method Details

.helpObject



36
37
38
39
# File 'lib/project_types/script/commands/create.rb', line 36

def self.help
  allowed_values = Script::Layers::Application::ExtensionPoints.types.map { |type| "{{cyan:#{type}}}" }
  ShopifyCli::Context.message('script.create.help', ShopifyCli::TOOL_NAME, allowed_values.join(', '))
end

Instance Method Details

#call(args, _name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/project_types/script/commands/create.rb', line 11

def call(args, _name)
  language = 'ts'
  cur_dir = @ctx.root

  form = Forms::Create.ask(@ctx, args, options.flags)
  return @ctx.puts(self.class.help) if form.nil?

  unless !form.name.empty? && form.extension_point && ScriptProject::SUPPORTED_LANGUAGES.include?(language)
    return @ctx.puts(self.class.help)
  end

  project = Layers::Application::CreateScript.call(
    ctx: @ctx,
    language: language,
    script_name: form.name,
    extension_point_type: form.extension_point
  )
  @ctx.puts(@ctx.message('script.create.change_directory_notice', project.script_name))
rescue Script::Errors::ScriptProjectAlreadyExistsError => e
  UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.create.error.operation_failed'))
rescue StandardError => e
  ScriptProject.cleanup(ctx: @ctx, script_name: form.name, root_dir: cur_dir) if form
  UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.create.error.operation_failed'))
end