Sha256: 9ce94198aee9fbaff9d9f53226db49dfaa490bb23ca243d34915e224b1f06f7c

Contents?: true

Size: 1.32 KB

Versions: 22

Compression:

Stored size: 1.32 KB

Contents

module Theme
  module Forms
    class Select < ShopifyCLI::Form
      attr_accessor :theme
      flag_arguments :root, :title, :exclude_roles, :include_foreign_developments

      def ask
        self.theme = CLI::UI::Prompt.ask(title, allow_empty: false) do |handler|
          themes.each do |theme|
            next if exclude_roles&.include?(theme.role)
            next if !include_foreign_developments && theme.foreign_development?
            handler.option("#{theme.name} #{theme_tags(theme)}") { theme }
          end
        end
      end

      private

      def themes
        @themes ||= ShopifyCLI::Theme::Theme.all(@ctx, root: root)
          .sort_by { |theme| theme_sort_order(theme) }
      end

      def theme_sort_order(theme)
        case theme.role
        when "live"
          0
        when "unpublished"
          1
        when "development"
          2
        else
          3
        end
      end

      def theme_tags(theme)
        color = case theme.role
        when "live"
          "green"
        when "unpublished"
          "yellow"
        when "development"
          "blue"
        else
          "italic"
        end

        tags = ["{{#{color}:[#{theme.role}]}}"]

        if theme.current_development?
          tags << "{{cyan:[yours]}}}}"
        end

        tags.join(" ")
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
shopify-cli-2.12.0 lib/project_types/theme/forms/select.rb
shopify-cli-2.11.2 lib/project_types/theme/forms/select.rb
shopify-cli-2.11.1 lib/project_types/theme/forms/select.rb
shopify-cli-2.11.0 lib/project_types/theme/forms/select.rb
shopify-cli-2.10.2 lib/project_types/theme/forms/select.rb
shopify-cli-2.10.1 lib/project_types/theme/forms/select.rb
shopify-cli-2.10.0 lib/project_types/theme/forms/select.rb
shopify-cli-2.9.0 lib/project_types/theme/forms/select.rb
shopify-cli-2.8.0 lib/project_types/theme/forms/select.rb
shopify-cli-2.7.4 lib/project_types/theme/forms/select.rb
shopify-cli-2.7.3 lib/project_types/theme/forms/select.rb
shopify-cli-2.7.2 lib/project_types/theme/forms/select.rb
shopify-cli-2.7.1 lib/project_types/theme/forms/select.rb
shopify-cli-2.7.0 lib/project_types/theme/forms/select.rb
shopify-cli-2.6.6 lib/project_types/theme/forms/select.rb
shopify-cli-2.6.5 lib/project_types/theme/forms/select.rb
shopify-cli-2.6.4 lib/project_types/theme/forms/select.rb
shopify-cli-2.6.3 lib/project_types/theme/forms/select.rb
shopify-cli-2.6.2 lib/project_types/theme/forms/select.rb
shopify-cli-2.6.1 lib/project_types/theme/forms/select.rb