Thursday, June 04, 2026 5:11:24 AM
> project show esm_website_v1
The unexpected heart of the ESM ecosystem. What started as a simple Rails dashboard has evolved into the command center for thousands of gaming communities, proving that sometimes the best infrastructure projects are the ones you never planned to build.
Details
> command_helper.rb
# frozen_string_literal: true

module CommandHelper
  include ArgumentFormatting

  def command_usage(command_name, arguments: {}, show_arguments: true)
    command = Command.all[command_name.to_sym]
    return command_name.to_s unless command

    if show_arguments && arguments.present?
      args_html = build_custom_arguments(command, arguments.with_indifferent_access)

      content_tag(:span, class: "command") do
        content_tag(:span, "#{command.usage} #{args_html}".html_safe)
      end
    elsif show_arguments
      render_component(CommandUsageDocsComponent, command: command)
    else
      content_tag(:span, class: "command") do
        content_tag(:span, command.usage)
      end
    end
  end

  def allowlist_roles(command)
    current_community.roles.map do |role|
      {
        value: role.id,
        label: role.name,
        selected: command.configuration.allowlisted_role_ids.include?(role.id)
      }
    end.to_json
  end

  private

  def build_custom_arguments(command, provided_arguments)
    command.arguments.join_map(" ") do |name, argument|
      value = provided_arguments[argument["name"]] || provided_arguments[argument["display_name"]]
      next unless value

      semantic_class = argument_semantic_class(name, argument)
      format_argument(argument["display_name"], "arg #{semantic_class}", value: value)
    end
  end
end
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 4294fb2