bin/netseg-update in ruby-jss-2.1.0b5 vs bin/netseg-update in ruby-jss-2.1.0

- old
+ new

@@ -53,17 +53,17 @@ PROG_NAME = File.basename($PROGRAM_NAME) USAGE = "Usage: #{PROG_NAME} [options] [--help] /path/to/file".freeze - POTENTIAL_COLUMNS = %i(name starting ending cidr mask).freeze + POTENTIAL_COLUMNS = %i[name starting ending cidr mask].freeze DEFAULT_CACHE_FILE = Pathname.new('~/.last_subnet_update').expand_path DEFAULT_DELIMITER = "\t".freeze - DEFAULT_COLUMNS = [:name, :starting, :ending].freeze + DEFAULT_COLUMNS = %i[name starting ending].freeze DEFAULT_MANUAL_PREFIX = 'Manual-'.freeze # define the cli opts CLI_OPTS = GetoptLong.new( @@ -82,11 +82,11 @@ ['--no-op', '-N', GetoptLong::NO_ARGUMENT] ) attr_reader :debug - def initialize(_args) + def initialize @getpass = $stdin.tty? ? :prompt : :stdin set_defaults parse_cli check_opts end # init @@ -181,11 +181,11 @@ -P, --port portnum - specify the JSS API port -U, --user username - specify the JSS API user -V, --no-verify-cert - Allow self-signed, unverified SSL certificate -T, --timeout secs - specify the JSS API timeout -N, --no-op - Don't make any changes in the JSS, just report what would - have be changed. + have been changed. -H, --help - show this help --debug - show the ruby backtrace when errors occur This program parses the input file line by line (possibly accounting for a header line). Each line defines the name and IP-range of a network segment. @@ -252,10 +252,11 @@ parsed_data = {} lines.each do |line| parsed_line = parse_a_data_line line next unless parsed_line + name = parsed_line.delete :name parsed_data[name] = parsed_line end parsed_names = parsed_data.keys jss_names = JSS::NetworkSegment.all_names.reject { |jss_name| jss_name.start_with? @manual_prefix } @@ -271,10 +272,11 @@ @columns.include?(:starting) raise "Columns must include either 'ending', 'cidr', or 'mask'" unless \ @columns.include?(:ending) || \ @columns.include?(:cidr) || \ @columns.include?(:mask) + @use_cidr = (@columns.include?(:cidr) || @columns.include?(:mask)) end def parse_a_data_line(line) parts = line.split(@delim).map(&:strip) @@ -294,15 +296,17 @@ def data_file_changed? # read in the file @raw_data = @file.read return true unless @cache_file.exist? + @raw_data != @cache_file.read end def cache_latest_data return if @noop + @cache_file.jss_save @raw_data end def update_network_segments puts 'Applying changes' @@ -373,10 +377,10 @@ ############################## # create the app and go begin debug = ARGV.include? '--debug' - app = App.new(ARGV) + app = App.new app.run rescue # handle exceptions not handled elsewhere puts "An error occurred: #{$ERROR_INFO}" puts 'Backtrace:' if debug