Class: ShopifyCli::Commands::Create

Inherits:
ShopifyCli::Command show all
Defined in:
lib/shopify-cli/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::Command

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

Methods included from Feature::Set

#hidden?, #hidden_feature

Constructor Details

This class inherits a constructor from ShopifyCli::Command

Class Method Details

.all_visible_typeObject



28
29
30
31
32
# File 'lib/shopify-cli/commands/create.rb', line 28

def self.all_visible_type
  ProjectType
    .load_all
    .select { |type| !type.hidden? }
end

.call(args, command_name) ⇒ Object



6
7
8
9
# File 'lib/shopify-cli/commands/create.rb', line 6

def self.call(args, command_name)
  ProjectType.load_type(args[0]) unless args.empty?
  super
end

.extended_helpObject



39
40
41
42
43
44
45
46
47
# File 'lib/shopify-cli/commands/create.rb', line 39

def self.extended_help
  "    \#{\n      all_visible_type.map do |type|\n        type.create_command.help\n      end.join(\"\\n\")\n    }\n  HELP\nend\n"

.helpObject



34
35
36
37
# File 'lib/shopify-cli/commands/create.rb', line 34

def self.help
  project_types = all_visible_type.map(&:project_type).sort.join(" | ")
  ShopifyCli::Context.message('core.create.help', ShopifyCli::TOOL_NAME, project_types)
end

Instance Method Details

#call(args, command_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shopify-cli/commands/create.rb', line 11

def call(args, command_name)
  unless args.empty?
    @ctx.puts(@ctx.message('core.create.error.invalid_app_type', args[0]))
    return @ctx.puts(self.class.help)
  end

  type_name = CLI::UI::Prompt.ask(@ctx.message('core.create.project_type_select')) do |handler|
    self.class.all_visible_type.each do |type|
      handler.option(type.project_name) { type.project_type }
    end
  end

  klass = ProjectType.load_type(type_name).create_command
  klass.ctx = @ctx
  klass.call(args, command_name, 'create')
end