Class: Theme::Command::Open

Inherits:
ShopifyCLI::Command::SubCommand show all
Includes:
Common::ShopHelper
Defined in:
lib/project_types/theme/commands/open.rb

Instance Attribute Summary

Attributes inherited from ShopifyCLI::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::ShopHelper

#shop

Methods inherited from ShopifyCLI::Command::SubCommand

call

Methods inherited from ShopifyCLI::Command

call, call_help, check_node_version, check_ruby_version, check_version, #initialize, options, prerequisite_task, recommend_default_node_range, recommend_default_ruby_range, recommend_node, recommend_ruby, 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



32
33
34
# File 'lib/project_types/theme/commands/open.rb', line 32

def self.help
  ShopifyCLI::Context.message("theme.open.help", ShopifyCLI::TOOL_NAME, ShopifyCLI::TOOL_NAME)
end

Instance Method Details

#call(_args, _name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/project_types/theme/commands/open.rb', line 21

def call(_args, _name)
  theme = find_theme(**options.flags)

  @ctx.puts(@ctx.message("theme.open.details", theme.name, theme.preview_url, theme.editor_url))
  if options.flags[:editor]
    @ctx.open_browser_url!(theme.editor_url)
  else
    @ctx.open_browser_url!(theme.preview_url)
  end
end

#development_themeObject



49
50
51
52
# File 'lib/project_types/theme/commands/open.rb', line 49

def development_theme
  theme = ShopifyCLI::Theme::DevelopmentTheme.find(@ctx)
  theme || not_found_error("development")
end

#find_theme(theme: nil, live: nil, development: nil, **_args) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/project_types/theme/commands/open.rb', line 36

def find_theme(theme: nil, live: nil, development: nil, **_args)
  return theme_by_identifier(theme) if theme
  return live_theme if live
  return development_theme if development

  select_theme
end

#live_themeObject



54
55
56
# File 'lib/project_types/theme/commands/open.rb', line 54

def live_theme
  ShopifyCLI::Theme::Theme.live(@ctx)
end

#not_found_error(identifier) ⇒ Object



58
59
60
# File 'lib/project_types/theme/commands/open.rb', line 58

def not_found_error(identifier)
  @ctx.abort(@ctx.message("theme.open.theme_not_found", identifier))
end

#select_themeObject



62
63
64
65
66
67
68
69
70
# File 'lib/project_types/theme/commands/open.rb', line 62

def select_theme
  form = Forms::Select.ask(
    @ctx,
    [],
    title: @ctx.message("theme.open.select", shop),
    root: nil
  )
  form&.theme
end

#theme_by_identifier(identifier) ⇒ Object



44
45
46
47
# File 'lib/project_types/theme/commands/open.rb', line 44

def theme_by_identifier(identifier)
  theme = ShopifyCLI::Theme::Theme.find_by_identifier(@ctx, identifier: identifier)
  theme || not_found_error(identifier)
end