Module: Space::Core::Commands

Defined in:
lib/space_core/commands.rb

Class Method Summary collapse

Class Method Details

.wrap(command) ⇒ Object

Render a multi-flag command with trailing " " continuations broken at "--flag" boundaries, continuation lines indented two spaces. Commands without "--" flags are returned unchanged.



10
11
12
13
14
15
16
17
18
# File 'lib/space_core/commands.rb', line 10

def wrap(command)
  parts = command.split(/(?= --)/)
  return command if parts.size <= 1

  parts.each_with_index.map do |part, i|
    segment = i.zero? ? part.rstrip : "  #{part.lstrip}"
    i < parts.size - 1 ? "#{segment} \\" : segment
  end.join("\n")
end