Method: Facter::Core::Execution::Posix#expand_command

Defined in:
lib/facter/custom_facts/core/execution/posix.rb

#expand_command(command) ⇒ Object

Since:

  • 2.0.0



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/facter/custom_facts/core/execution/posix.rb', line 37

def expand_command(command)
  exe = nil
  args = nil

  match = command.match(DOUBLE_QUOTED_COMMAND) || command.match(SINGLE_QUOTED_COMMAND)
  if match
    exe, args = match.captures
  else
    exe, args = command.split(/ /, 2)
  end

  return unless exe && (expanded = which(exe))

  expanded = expanded.dup
  expanded = +"'#{expanded}'" if /\s/.match?(expanded)
  expanded << " #{args}" if args

  expanded
end