lib/puppetfile-resolver/util.rb in puppetfile-resolver-0.5.0 vs lib/puppetfile-resolver/util.rb in puppetfile-resolver-0.6.0

- old
+ new

@@ -1,7 +1,9 @@ # frozen_string_literal: true +require 'open3' + module PuppetfileResolver module Util def self.symbolise_object(object) case # rubocop:disable Style/EmptyCaseCondition Ignore when object.is_a?(Hash) @@ -40,8 +42,25 @@ start_args.concat([proxy.host, proxy.port, proxy.user, proxy.password]) end Net::HTTP.start(*start_args, http_options) { |http| return http.request(Net::HTTP::Get.new(uri)) } nil + end + + # @summary runs the command on the shell + # @param cmd [Array] an array of command and args + # @returns [Array] the result of running the comand and the process + # @example run_command(['git', '--version']) + def self.run_command(cmd) + Open3.capture3(*cmd) + end + + # @summary checks if git is installed and on the path + # @returns [Boolean] true if git is found in the path + def self.git? + Open3.capture3('git', '--version') + true + rescue Errno::ENOENT + false end end end