Sha256: e2e349189d73b6644f06ffc0b01effae46fe99ae4d371f81689dec81453c86e2

Contents?: true

Size: 995 Bytes

Versions: 43

Compression:

Stored size: 995 Bytes

Contents

module Rack::App::CLI::DefaultCommands::ListCommands

  extend self

  PRESERVED_KEYWORDS = ['commands', 'help', 'routes']

  def get_message(known_commands)
    puts_collection = []

    add_header(puts_collection)

    list_command_name = 'commands'
    rjust = known_commands.keys.push(*PRESERVED_KEYWORDS).map(&:to_s).map(&:length).max + 3

    puts_collection << [list_command_name.to_s.rjust(rjust), 'list all available command'].join('  ')
    puts_collection << ['routes'.to_s.rjust(rjust), 'list all available endpoint'].join('  ')

    known_commands.sort_by { |name, _| name.to_s }.each do |name, command|
      puts_collection << [name.to_s.rjust(rjust), command.class.description].join('  ')
    end

    puts_collection.join("\n")
  end

  protected

  def add_header(puts_collection)
    cmd_file_name = File.basename($0)
    puts_collection << "Usage: #{cmd_file_name} <command> [options] <args>\n\n"
    puts_collection << "Some useful #{cmd_file_name} commands are:"
  end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
rack-app-7.1.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-7.0.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.8.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.7.1 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.7.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.6.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.5.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.4.1 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.4.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.3.3 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.3.2 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.3.1 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.3.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.2.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.1.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-6.0.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-5.12.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-5.11.1 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-5.11.0 lib/rack/app/cli/default_commands/list_commands.rb
rack-app-5.10.2 lib/rack/app/cli/default_commands/list_commands.rb