Module: Dry::CLI::Banner Private
- Extended by:
- ColorMethods, WordWrap
- Defined in:
- lib/dry/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
Defined Under Namespace
Modules: ColorMethods
Constant Summary collapse
- DESCRIPTION_START =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
25
Constants included from ColorMethods
ColorMethods::COLOR_METHODS, ColorMethods::DECORATIONS
Class Method Summary collapse
- .arguments(command) ⇒ Object private
- .build_subcommands_list(subcommands) ⇒ Object private
-
.call(command, name) ⇒ Object
private
Prints command banner.
- .color_arguments(string) ⇒ Object private
- .color_command(string) ⇒ Object private
- .color_enabled? ⇒ Boolean private
- .color_header(string) ⇒ Object private
- .command_arguments(command) ⇒ Object private
- .command_description(command) ⇒ Object private
- .command_examples(command, name) ⇒ Object private
- .command_name(name) ⇒ Object private
- .command_name_and_arguments(command, name) ⇒ Object private
- .command_options(command) ⇒ Object private
- .command_subcommands(command) ⇒ Object private
- .disable_color! ⇒ Object private
- .enable_color! ⇒ Object private
- .extended_command_arguments(command) ⇒ Object private
- .extended_command_options(command) ⇒ Object private
Methods included from WordWrap
Methods included from ColorMethods
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.
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/dry/cli/banner.rb', line 239 def self.arguments(command) 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 |
.build_subcommands_list(subcommands) ⇒ 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.
286 287 288 289 290 |
# File 'lib/dry/cli/banner.rb', line 286 def self.build_subcommands_list(subcommands) subcommands.map do |subcommand_name, subcommand| " #{yellow(subcommand_name.ljust(12))} # #{red(wrap_description(subcommand.command.description))}`" end.join("\n") end |
.call(command, name) ⇒ 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
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/dry/cli/banner.rb', line 169 def self.call(command, name) [ command_name(name), command_name_and_arguments(command, name), command_description(command), command_subcommands(command), command_arguments(command), (command), command_examples(command, name) ].compact.join("\n") end |
.color_arguments(string) ⇒ 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.
158 159 160 |
# File 'lib/dry/cli/banner.rb', line 158 def self.color_arguments(string) color_enabled? ? yellow.italic(string) : string end |
.color_command(string) ⇒ 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.
154 155 156 |
# File 'lib/dry/cli/banner.rb', line 154 def self.color_command(string) color_enabled? ? green.bold(string) : string end |
.color_enabled? ⇒ Boolean
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.
136 137 138 |
# File 'lib/dry/cli/banner.rb', line 136 def self.color_enabled? @color_enabled end |
.color_header(string) ⇒ 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.
150 151 152 |
# File 'lib/dry/cli/banner.rb', line 150 def self.color_header(string) color_enabled? ? bright_blue.bold(string.upcase) : string.upcase 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.
225 226 227 228 229 |
# File 'lib/dry/cli/banner.rb', line 225 def self.command_arguments(command) return if command.arguments.empty? "\n#{color_header("Arguments")}:\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.
211 212 213 214 215 |
# File 'lib/dry/cli/banner.rb', line 211 def self.command_description(command) return if command.description.nil? "\n#{color_header("Description")}:\n #{command.description}" end |
.command_examples(command, name) ⇒ 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.
199 200 201 202 203 204 205 206 207 |
# File 'lib/dry/cli/banner.rb', line 199 def self.command_examples(command, name) return if command.examples.empty? "\n#{color_header("Examples")}:\n" + command.examples.map do |example| args, desc = example.split("#") comment_line = (desc.nil? || desc.empty?) ? "" : " #{bright_black("##{desc}")}\n" comment_line + " #{color_command(name)} #{color_arguments(args)}" end.join("\n\n") end |
.command_name(name) ⇒ 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.
183 184 185 |
# File 'lib/dry/cli/banner.rb', line 183 def self.command_name(name) color_header("Command:\n") + " #{yellow(name)}" end |
.command_name_and_arguments(command, name) ⇒ 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.
189 190 191 192 193 194 195 |
# File 'lib/dry/cli/banner.rb', line 189 def self.command_name_and_arguments(command, name) usage = "\n#{color_header("Usage")}:\n #{color_command(name)}#{color_arguments(arguments(command))}" return usage + " | #{name} SUBCOMMAND" if command.subcommands.any? usage 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.
233 234 235 |
# File 'lib/dry/cli/banner.rb', line 233 def self.(command) "\n#{color_header("Options")}:\n#{(command)}" end |
.command_subcommands(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.
217 218 219 220 221 |
# File 'lib/dry/cli/banner.rb', line 217 def self.command_subcommands(command) return if command.subcommands.empty? "\n#{color_header("Subcommands")}:\n#{build_subcommands_list(command.subcommands)}" end |
.disable_color! ⇒ 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.
145 146 147 148 |
# File 'lib/dry/cli/banner.rb', line 145 def self.disable_color! @pastel = nil @color_enabled = false end |
.enable_color! ⇒ 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.
140 141 142 143 |
# File 'lib/dry/cli/banner.rb', line 140 def self.enable_color! @pastel = nil @color_enabled = true 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.
254 255 256 257 258 |
# File 'lib/dry/cli/banner.rb', line 254 def self.extended_command_arguments(command) command.arguments.map do |argument| " #{argument.name.to_s.upcase.ljust(DESCRIPTION_START)} # #{"REQUIRED " if argument.required?}#{wrap_description(argument.desc, prefix: " " * 31 + "# ")}" 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.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/dry/cli/banner.rb', line 263 def self.(command) result = command..map do |option| name = Inflector.dasherize(option.name) name = if option.boolean? "[no-]#{name}" elsif option.flag? name elsif option.array? "#{name}=VALUE1,VALUE2,.." else "#{name}=VALUE" end name = "#{name}, #{option.alias_names.join(", ")}" if option.aliases.any? name = " --#{name.ljust(DESCRIPTION_START)}" name = "#{name} # #{wrap_description(option.desc, prefix: " " * 31 + "# ")}" name = "#{name}, default: #{option.default.inspect}" unless option.default.nil? name end result << " --#{"help, -h".ljust(DESCRIPTION_START)} # Print this help" result.join("\n") end |