class CfScript::Command::Line
Attributes
args[R]
bin[R]
env[R]
flags[R]
name[R]
options[R]
type[R]
Public Class Methods
new(env, bin, type, name, args = [])
click to toggle source
# File lib/cf_script/command/line.rb, line 12 def initialize(env, bin, type, name, args = []) @env = env @bin = bin @type = type @name = name @options = args.last.is_a?(Hash) ? args.pop : {} @flags = options.delete(:flags) || [] @args = args end
Public Instance Methods
hide_sensitive()
click to toggle source
# File lib/cf_script/command/line.rb, line 28 def hide_sensitive case name when :auth hide_parts(-1, 'PASSWORD HIDDEN') when :login hide_option('-p', 'PASSWORD HIDDEN') else line end end
line()
click to toggle source
# File lib/cf_script/command/line.rb, line 23 def line @line ||= format end
Also aliased as: to_s
Private Instance Methods
format()
click to toggle source
# File lib/cf_script/command/line.rb, line 41 def format list = [bin] list << format_name list << format_args list << format_options list << format_flags list.compact.reject(&:empty?).join(' ').gsub(/\s+/, ' ') end
format_args()
click to toggle source
# File lib/cf_script/command/line.rb, line 56 def format_args list = [] args.compact.each do |arg| list << arg.to_s.shellescape end list.join(' ') end
format_flags()
click to toggle source
# File lib/cf_script/command/line.rb, line 76 def format_flags list = [] flags.each do |name| flag = name.to_s.gsub('_', '-') list << unless flag =~ /\A(--|-[[:alnum:]])/ if flag.length == 1 "-#{flag}" else "--#{flag}" end else flag end end list.join(' ') end
format_name()
click to toggle source
# File lib/cf_script/command/line.rb, line 52 def format_name name.to_s.gsub(/_/, '-') end
format_options()
click to toggle source
# File lib/cf_script/command/line.rb, line 66 def format_options list = [] options.each do |name, value| list << "-#{name} #{value.to_s.shellescape}" unless value.nil? end list.join(' ') end
hide_option(option, with = 'HIDDEN')
click to toggle source
# File lib/cf_script/command/line.rb, line 102 def hide_option(option, with = 'HIDDEN') line.gsub(/#{option}\s+(['"][^'"]+['"]|[\S]+)/, "#{option} [#{with}]") end
hide_parts(parts, with = 'HIDDEN')
click to toggle source
# File lib/cf_script/command/line.rb, line 96 def hide_parts(parts, with = 'HIDDEN') bits = line.split(/\s+(?=(?:[^"']|"[^"]*"|'[^']*')*$)/) bits[parts] = "[#{with}]" bits.join(' ') end