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.36.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.35.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.34.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.33.1 lib/shopify_cli/commands/help.rb
shopify-cli-2.33.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.32.1 lib/shopify_cli/commands/help.rb
shopify-cli-2.32.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.31.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.30.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.29.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.28.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.27.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.26.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.25.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.24.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.23.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.22.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.21.0 lib/shopify_cli/commands/help.rb
shopify-cli-2.20.1 lib/shopify_cli/commands/help.rb
shopify-cli-2.20.0 lib/shopify_cli/commands/help.rb