Sha256: 47c5b17adfcb6be481b853c796bfada2a7d9030959666bc365e1f850cef05df7

Contents?: true

Size: 1.61 KB

Versions: 9

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true
require "shopify_cli"

module Rails
  class Command
    class Generate < ShopifyCli::SubCommand
      prerequisite_task ensure_project_type: :rails

      autoload :Webhook, Project.project_filepath("commands/generate/webhook")

      WEBHOOK = "webhook"

      def call(args, _name)
        subcommand = args.shift
        case subcommand
        when WEBHOOK
          Rails::Command::Generate::Webhook.start(@ctx, args)
        else
          @ctx.puts(self.class.help)
        end
      end

      def self.help
        ShopifyCli::Context.message("rails.generate.help", ShopifyCli::TOOL_NAME)
      end

      def self.extended_help
        extended_help = "{{bold:Subcommands:}}\n"
        subcommand_registry.resolved_commands.sort.each do |name, klass|
          extended_help += "  {{cyan:#{name}}}: "

          if (subcmd_help = klass.help)
            extended_help += subcmd_help.gsub("\n  ", "\n    ")
          end
          extended_help += "\n"
        end
        extended_help += ShopifyCli::Context.message("rails.generate.extended_help", ShopifyCli::TOOL_NAME)
      end

      def self.run_generate(script, name, ctx)
        Gem.gem_path(ctx)
        stat = ctx.system(script)
        unless stat.success?
          ctx.abort(response(stat.exitstatus, name, ctx))
        end
      end

      def self.response(code, name, ctx)
        case code
        when 1
          ctx.message("rails.generate.error.generic", name)
        when 2
          ctx.message("rails.generate.error.name_exists", name)
        else
          ctx.message("rails.error.generic")
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shopify-cli-2.4.0 lib/project_types/rails/commands/generate.rb
shopify-cli-2.3.0 lib/project_types/rails/commands/generate.rb
shopify-cli-2.2.2 lib/project_types/rails/commands/generate.rb
shopify-cli-2.2.1 lib/project_types/rails/commands/generate.rb
shopify-cli-2.2.0 lib/project_types/rails/commands/generate.rb
shopify-cli-2.1.0 lib/project_types/rails/commands/generate.rb
shopify-cli-2.0.2 lib/project_types/rails/commands/generate.rb
shopify-cli-2.0.1 lib/project_types/rails/commands/generate.rb
shopify-cli-2.0.0 lib/project_types/rails/commands/generate.rb