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
Direct Known Subclasses
Extension::Commands::ExtensionCommand, Node::Commands::Deploy, Node::Commands::Generate, Node::Commands::Open, Node::Commands::Populate, Node::Commands::Serve, Node::Commands::Tunnel, Rails::Commands::Deploy, Rails::Commands::Generate, Rails::Commands::Open, Rails::Commands::Populate, Rails::Commands::Serve, Rails::Commands::Tunnel, Script::Commands::Disable, Script::Commands::Enable, Script::Commands::Push, ShopifyCli::Commands::Config, ShopifyCli::Commands::Connect, ShopifyCli::Commands::Create, ShopifyCli::Commands::Help, ShopifyCli::Commands::Logout, ShopifyCli::Commands::System, ShopifyCli::Commands::Version, SubCommand
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.
64
65
66
67
68
|
# File 'lib/shopify-cli/command.rb', line 64
def initialize(ctx = nil)
super()
@ctx = ctx || ShopifyCli::Context.new
self.options = Options.new
end
|
Class Attribute Details
.ctx=(value) ⇒ Object
12
13
14
|
# File 'lib/shopify-cli/command.rb', line 12
def ctx=(value)
@ctx = value
end
|
.task_registry ⇒ Object
54
55
56
|
# File 'lib/shopify-cli/command.rb', line 54
def task_registry
@task_registry || ShopifyCli::Tasks::Registry
end
|
Instance Attribute Details
#ctx=(value) ⇒ Object
8
9
10
|
# File 'lib/shopify-cli/command.rb', line 8
def ctx=(value)
@ctx = value
end
|
#options ⇒ Object
Returns the value of attribute options.
9
10
11
|
# File 'lib/shopify-cli/command.rb', line 9
def options
@options
end
|
Class Method Details
.call(args, command_name) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/shopify-cli/command.rb', line 14
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, resolved_name, command_name)
else
cmd = new(@ctx)
cmd.options.parse(@_options, args)
return call_help(command_name) if cmd.options.help
run_prerequisites
cmd.call(args, command_name)
end
end
|
.call_help(*cmds) ⇒ Object
58
59
60
61
|
# File 'lib/shopify-cli/command.rb', line 58
def call_help(*cmds)
help = Commands::Help.new(@ctx)
help.call(cmds, nil)
end
|
.options(&block) ⇒ Object
29
30
31
|
# File 'lib/shopify-cli/command.rb', line 29
def options(&block)
@_options = block
end
|
.prerequisite_task(*tasks) ⇒ Object
45
46
47
48
|
# File 'lib/shopify-cli/command.rb', line 45
def prerequisite_task(*tasks)
@prerequisite_tasks ||= []
@prerequisite_tasks += tasks
end
|
.run_prerequisites ⇒ Object
50
51
52
|
# File 'lib/shopify-cli/command.rb', line 50
def run_prerequisites
(@prerequisite_tasks || []).each { |task| task_registry[task]&.call(@ctx) }
end
|
.subcommand(const, cmd, path = nil) ⇒ Object
33
34
35
36
|
# File 'lib/shopify-cli/command.rb', line 33
def subcommand(const, cmd, path = nil)
autoload(const, path) if path
subcommand_registry.add(->() { const_get(const) }, cmd.to_s)
end
|
.subcommand_registry ⇒ Object
38
39
40
41
42
43
|
# File 'lib/shopify-cli/command.rb', line 38
def subcommand_registry
@subcommand_registry ||= CLI::Kit::CommandRegistry.new(
default: nil,
contextual_resolver: nil,
)
end
|