Module: Dry::CLI::Banner

Defined in:
lib/patches/dry-cli.rb

Class Method Summary collapse

Class Method Details

.call(command, name) ⇒ String

Overwrites the original ‘call’ method to accommodate a custom header and footer for the help text.

Parameters:

  • command (Class)

    the the command class

  • name (String)

    command line without help option

Returns:

  • (String)

    modified help text



79
80
81
82
83
84
85
86
87
88
# File 'lib/patches/dry-cli.rb', line 79

def call(command, name)
  help_text = original_call(command, name)

			my_header, my_footer = command_help_wrapper(command)

  help_text.prepend(my_header)
  help_text += my_footer

  help_text
end

.command_help_wrapper(command) ⇒ Array<String>

Provides the header and footer for the received command.

Parameters:

  • command (Class)

    the command class

Returns:

  • (Array<String>)

    an array with the header at the 0 index and the footer at the 1 index



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/patches/dry-cli.rb', line 96

def command_help_wrapper(command)
	global_header 	= Dry::CLI::Command.global_header
	global_footer 	= Dry::CLI::Command.global_footer
  command_header 	= command.header
  command_footer 	= command.footer

  my_header = ""
  my_header += global_header + "\n"	unless (global_header.nil? || global_header.empty?)
  my_header += command_header+ "\n" unless (command_header.nil?|| command_header.empty?)

  my_footer = ""
  my_footer += "\n" + command_footer 	unless (command_footer.nil?|| command_footer.empty?)
  my_footer += "\n" + global_footer 	unless (global_footer.nil? || global_footer.empty?)

	[my_header, my_footer]
end

.original_callObject



71
# File 'lib/patches/dry-cli.rb', line 71

alias_method :original_call, :call