Module: Gauntlt::Support::CliHelper

Defined in:
lib/gauntlt/attack_adapters/support/cli_helper.rb

Instance Method Summary collapse

Instance Method Details

#cli_installed?(bin_name) ⇒ Boolean

Returns:

  • (Boolean)

10
11
12
# File 'lib/gauntlt/attack_adapters/support/cli_helper.rb', line 10

def cli_installed?(bin_name)
  `which #{bin_name}` && $CHILD_STATUS.success?
end

#ensure_cli_installed(bin) ⇒ Object


14
15
16
# File 'lib/gauntlt/attack_adapters/support/cli_helper.rb', line 14

def ensure_cli_installed(bin)
  raise "#{bin} is not installed or is not in your path" unless cli_installed?(bin)
end

#ensure_shell_variable_set(shell_variable) ⇒ Object


18
19
20
# File 'lib/gauntlt/attack_adapters/support/cli_helper.rb', line 18

def ensure_shell_variable_set(shell_variable)
  raise "#{shell_variable} is not set" unless shell_variable_exists?(shell_variable)
end

#get_cli_version(bin_name) ⇒ Object

this should succeed in getting the version of a command in most situations


27
28
29
# File 'lib/gauntlt/attack_adapters/support/cli_helper.rb', line 27

def get_cli_version(bin_name)
  return `#{bin_name} --version`.scan(/((\d+\.)?(\d+\.)?(\*|\d+))/)[0][0]
end

#get_shell_variable(shell_variable) ⇒ Object


22
23
24
# File 'lib/gauntlt/attack_adapters/support/cli_helper.rb', line 22

def get_shell_variable(shell_variable)
  ENV[shell_variable]
end

#shell_variable_exists?(shell_variable) ⇒ Boolean

Returns:

  • (Boolean)

31
32
33
34
# File 'lib/gauntlt/attack_adapters/support/cli_helper.rb', line 31

def shell_variable_exists?(shell_variable)
  path = get_shell_variable(shell_variable)
  File.exists?(path) if path
end