Class: ShopifyCLI::Command
- Inherits:
-
CLI::Kit::BaseCommand
- Object
- CLI::Kit::BaseCommand
- ShopifyCLI::Command
show all
- Extended by:
- Feature::Set
- Defined in:
- lib/shopify_cli/command.rb,
lib/shopify_cli/command/sub_command.rb,
lib/shopify_cli/command/app_sub_command.rb,
lib/shopify_cli/command/project_command.rb
Direct Known Subclasses
ProjectCommand, SubCommand, ShopifyCLI::Commands::App, ShopifyCLI::Commands::App::Create, ShopifyCLI::Commands::Config, ShopifyCLI::Commands::Help, ShopifyCLI::Commands::Login, ShopifyCLI::Commands::Logout, ShopifyCLI::Commands::Populate, ShopifyCLI::Commands::Reporting, ShopifyCLI::Commands::Store, ShopifyCLI::Commands::Switch, ShopifyCLI::Commands::System, ShopifyCLI::Commands::Version, ShopifyCLI::Commands::Whoami, ProjectCommand
Defined Under Namespace
Classes: AppSubCommand, PrerequisiteTask, ProjectCommand, SubCommand, VersionRange
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
hidden?, hidden_feature
Constructor Details
#initialize(ctx = nil) ⇒ Command
Returns a new instance of Command.
167
168
169
170
171
|
# File 'lib/shopify_cli/command.rb', line 167
def initialize(ctx = nil)
super()
@ctx = ctx || ShopifyCLI::Context.new
self.options = Options.new
end
|
Class Attribute Details
.ctx=(value) ⇒ Object
19
20
21
|
# File 'lib/shopify_cli/command.rb', line 19
def ctx=(value)
@ctx = value
end
|
.task_registry ⇒ Object
148
149
150
|
# File 'lib/shopify_cli/command.rb', line 148
def task_registry
@task_registry || ShopifyCLI::Tasks::Registry
end
|
Instance Attribute Details
#ctx=(value) ⇒ Object
15
16
17
|
# File 'lib/shopify_cli/command.rb', line 15
def ctx=(value)
@ctx = value
end
|
#options ⇒ Object
Returns the value of attribute options.
16
17
18
|
# File 'lib/shopify_cli/command.rb', line 16
def options
@options
end
|
Class Method Details
.call(args, command_name) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/shopify_cli/command.rb', line 21
def call(args, command_name, *)
subcommand, resolved_name = subcommand_registry.lookup_command(args.first)
if subcommand
subcommand.ctx = @ctx
subcommand.task_registry = @task_registry
subcommand.call(args.drop(1), resolved_name, command_name)
else
cmd = new(@ctx)
cmd.options.parse(@_options, args)
return call_help(command_name) if cmd.options.help
check_ruby_version
check_node_version
run_prerequisites
cmd.call(args, command_name)
end
rescue OptionParser::InvalidOption => error
arg = error.args.first
store_name = arg.match(/\A--(?<store_name>.*\.myshopify\.com)\z/)&.[](:store_name)
if store_name && !arg.match?(/\A--(store|shop)=/)
store_name = store_name.sub(%r{\A(.*=)?(https?://)?}, "")
raise ShopifyCLI::Abort,
@ctx.message("core.errors.option_parser.invalid_option_store_equals", arg, store_name)
end
raise ShopifyCLI::Abort, @ctx.message("core.errors.option_parser.invalid_option", arg)
rescue OptionParser::MissingArgument => error
arg = error.args.first
raise ShopifyCLI::Abort, @ctx.message("core.errors.option_parser.missing_argument", arg)
end
|
.call_help(*cmds) ⇒ Object
152
153
154
155
|
# File 'lib/shopify_cli/command.rb', line 152
def call_help(*cmds)
help = Commands::Help.new(@ctx)
help.call(cmds, nil)
end
|
.check_node_version ⇒ Object
109
110
111
112
113
114
115
116
117
|
# File 'lib/shopify_cli/command.rb', line 109
def check_node_version
return unless @compatible_node_range
check_version(
Environment.node_version,
range: @compatible_node_range,
runtime: "Node"
)
end
|
.check_ruby_version ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/shopify_cli/command.rb', line 87
def check_ruby_version
check_version(
Environment.ruby_version,
range: @compatible_ruby_range,
runtime: "Ruby"
)
end
|
.check_version(version, range:, runtime:, context: Context.new) ⇒ Object
.options(&block) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/shopify_cli/command.rb', line 52
def options(&block)
existing_options = @_options
@_options = ->(parser, flags) {
existing_options&.call(parser, flags)
block.call(parser, flags)
}
end
|
.prerequisite_task(*tasks_without_args, **tasks_with_args) ⇒ Object
136
137
138
139
140
|
# File 'lib/shopify_cli/command.rb', line 136
def prerequisite_task(*tasks_without_args, **tasks_with_args)
@prerequisite_tasks ||= []
@prerequisite_tasks += tasks_without_args.map { |t| PrerequisiteTask.new(t) }
@prerequisite_tasks += tasks_with_args.map { |t, args| PrerequisiteTask.new(t, args) }
end
|
.recommend_default_node_range ⇒ Object
.recommend_default_ruby_range ⇒ Object
.recommend_node(from:, to:) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/shopify_cli/command.rb', line 95
def recommend_node(from:, to:)
@compatible_node_range = VersionRange.new(
from: Semantic::Version.new(from),
to: Semantic::Version.new(to)
)
end
|
.recommend_ruby(from:, to:) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/shopify_cli/command.rb', line 73
def recommend_ruby(from:, to:)
@compatible_ruby_range = VersionRange.new(
from: Semantic::Version.new(from),
to: Semantic::Version.new(to)
)
end
|
.run_prerequisites ⇒ Object
142
143
144
145
146
|
# File 'lib/shopify_cli/command.rb', line 142
def run_prerequisites
(@prerequisite_tasks || []).each do |task|
task_registry[task.name]&.call(@ctx, *task.args)
end
end
|
.subcommand(const, cmd, path = nil) ⇒ Object
61
62
63
64
|
# File 'lib/shopify_cli/command.rb', line 61
def subcommand(const, cmd, path = nil)
autoload(const, path) if path
subcommand_registry.add(->() { const_get(const) }, cmd.to_s)
end
|
.subcommand_registry ⇒ Object
66
67
68
69
70
71
|
# File 'lib/shopify_cli/command.rb', line 66
def subcommand_registry
@subcommand_registry ||= CLI::Kit::CommandRegistry.new(
default: nil,
contextual_resolver: nil,
)
end
|