Module: Hanami::CLI::Banner Private

Defined in:
lib/hanami/cli/banner.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Command banner

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.arguments(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



80
81
82
83
84
85
86
87
88
89
# File 'lib/hanami/cli/banner.rb', line 80

def self.arguments(command) # rubocop:disable Metrics/AbcSize
  required_arguments = command.required_arguments
  optional_arguments = command.optional_arguments

  required = required_arguments.map { |arg| arg.name.upcase }.join(' ') if required_arguments.any?
  optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(' ') if optional_arguments.any?
  result = [required, optional].compact

  " #{result.join(' ')}" unless result.empty?
end

.call(command, out) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prints command banner

Parameters:

Since:

  • 0.1.0



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hanami/cli/banner.rb', line 17

def self.call(command, out)
  output = [
    command_name(command),
    command_name_and_arguments(command),
    command_description(command),
    command_arguments(command),
    command_options(command),
    command_examples(command)
  ].compact.join("\n")

  out.puts output
end

.command_arguments(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



60
61
62
63
64
# File 'lib/hanami/cli/banner.rb', line 60

def self.command_arguments(command)
  return if command.arguments.empty?

  "\nArguments:\n#{extended_command_arguments(command)}"
end

.command_description(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



52
53
54
55
56
# File 'lib/hanami/cli/banner.rb', line 52

def self.command_description(command)
  return if command.description.nil?

  "\nDescription:\n  #{command.description}"
end

.command_examples(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



44
45
46
47
48
# File 'lib/hanami/cli/banner.rb', line 44

def self.command_examples(command)
  return if command.examples.empty?

  "\nExamples:\n#{command.examples.map { |example| "  #{full_command_name(command)} #{example}" }.join("\n")}"
end

.command_name(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



32
33
34
# File 'lib/hanami/cli/banner.rb', line 32

def self.command_name(command)
  "Command:\n  #{full_command_name(command)}"
end

.command_name_and_arguments(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



38
39
40
# File 'lib/hanami/cli/banner.rb', line 38

def self.command_name_and_arguments(command)
  "\nUsage:\n  #{full_command_name(command)}#{arguments(command)}"
end

.command_options(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



68
69
70
# File 'lib/hanami/cli/banner.rb', line 68

def self.command_options(command)
  "\nOptions:\n#{extended_command_options(command)}"
end

.extended_command_arguments(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



93
94
95
96
97
# File 'lib/hanami/cli/banner.rb', line 93

def self.extended_command_arguments(command)
  command.arguments.map do |argument|
    "  #{argument.name.to_s.upcase.ljust(20)}\t# #{'REQUIRED ' if argument.required?}#{argument.desc}"
  end.join("\n")
end

.extended_command_options(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

Since:

  • 0.1.0



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/hanami/cli/banner.rb', line 104

def self.extended_command_options(command)
  result = command.options.map do |option|
    name = Utils::String.dasherize(option.name)
    name = if option.boolean?
             "[no-]#{name}"
           else
             "#{name}=VALUE"
           end

    name = "#{name}, #{option.aliases.map { |a| a.start_with?('--') ? "#{a}=VALUE" : "#{a} VALUE" }.join(', ')}" unless option.aliases.empty?
    name = "  --#{name.ljust(30)}"
    name = "#{name}\t# #{option.desc}"
    name = "#{name}, default: #{option.default.inspect}" unless option.default.nil?
    name
  end

  result << "  --#{'help, -h'.ljust(30)}\t# Print this help"
  result.join("\n")
end

.full_command_name(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



74
75
76
# File 'lib/hanami/cli/banner.rb', line 74

def self.full_command_name(command)
  ProgramName.call(command.command_name)
end