Sha256: f41291815a4e9634df8205b11e4cee9ea711b99b0a72d2bff43344cf04b401ec

Contents?: true

Size: 1.32 KB

Versions: 57

Compression:

Stored size: 1.32 KB

Contents

require "shopify_cli"

module ShopifyCLI
  module Commands
    class Help < ShopifyCLI::Command
      def call(args, _name)
        command = args.shift
        if command && command != "help"
          if Registry.exist?(command)
            cmd, _ = Registry.lookup_command(command)
            subcmd, _ = cmd.subcommand_registry.lookup_command(args.first)
            if subcmd
              display_help(subcmd)
            else
              display_help(cmd)
            end
            return
          else
            @ctx.puts(@ctx.message("core.help.error.command_not_found", command))
          end
        end

        preamble = @ctx.message("core.help.preamble", ShopifyCLI::TOOL_NAME)
        @ctx.puts(preamble)

        available_commands = resolved_commands.select { |_name, c| !c.hidden? }

        available_commands.each do |name, klass|
          next if name == "help"
          @ctx.puts("{{command:#{name}}}: #{klass.help}\n")
        end
      end

      private

      def display_help(klass)
        output = klass.help
        if klass.respond_to?(:extended_help)
          output += "\n"
          output += klass.extended_help
        end
        @ctx.puts(output)
      end

      def resolved_commands
        ShopifyCLI::Commands::Registry
          .resolved_commands
          .sort
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
shopify-cli-2.19.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.18.1 lib/shopify_cli/commands/help.rb
shopify-cli-2.18.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.17.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.16.1 lib/shopify_cli/commands/help.rb
shopify-cli-2.16.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.15.6 lib/shopify_cli/commands/help.rb
shopify-cli-2.15.5 lib/shopify_cli/commands/help.rb
shopify-cli-2.15.4 lib/shopify_cli/commands/help.rb
shopify-cli-2.15.3 lib/shopify_cli/commands/help.rb
shopify-cli-2.15.2 lib/shopify_cli/commands/help.rb
shopify-cli-2.15.1 lib/shopify_cli/commands/help.rb
shopify-cli-2.15.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.14.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.13.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.12.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.11.2 lib/shopify_cli/commands/help.rb
shopify-cli-2.11.1 lib/shopify_cli/commands/help.rb
shopify-cli-2.11.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.10.2 lib/shopify_cli/commands/help.rb