module Knife::Zero::Helper

Public Class Methods

chef_version_available?(version) click to toggle source
# File lib/knife-zero/helper.rb, line 17
def self.chef_version_available?(version)
  return true if version == 'latest'

  chefgem_metaurl = 'https://rubygems.org/api/v1/versions/chef.json'
  begin
    c_versions = JSON.parse(URI.parse(chefgem_metaurl).open.read).map { |v| v['number'] }
    c_versions.include?(version)
  rescue => e # rubocop:disable Style/RescueStandardError
    puts e.inspect
    puts "Some Error occurerd while fetching versions from #{chefgem_metaurl}. Please try again later."
    exit
  end
end
hook_shell_out!(event, ui, *command_args) click to toggle source
# File lib/knife-zero/helper.rb, line 31
def self.hook_shell_out!(event, ui, *command_args)
  ui.info ui.color("Execute command hook in #{event}.", :green)
  begin
    ui.info shell_out!(*command_args).stdout
  rescue => e # rubocop:disable Style/RescueStandardError
    ui.error e.inspect
    raise e
  end
end
required_chef_version?(ver) click to toggle source
# File lib/knife-zero/helper.rb, line 41
def self.required_chef_version?(ver)
  Gem::Version.new(Chef::VERSION) >= Gem::Version.new(ver)
end
zero_remote_port() click to toggle source
# File lib/knife-zero/helper.rb, line 8
def self.zero_remote_port
  return ::Chef::Config[:remote_chef_zero_port] if ::Chef::Config[:remote_chef_zero_port]

  chef_zero_port = ::Chef::Config[:chef_zero_port] ||
                   ::Chef::Config[:knife][:chef_zero_port] ||
                   8889
  chef_zero_port + 10_000
end