#!/usr/bin/env ruby Main = self public require 'Paludis' require 'getoptlong' require 'pathname' require 'shellwords' require 'readline' begin require 'irb-pager' rescue LoadError STDERR.puts <= 2 && Readline::HISTORY[-2] == line) line end def execute x case x when /^\d+$/ m = list[x.to_i] raise UsageError, "Unknown index #{x}" unless m self.selected = m when cmds instance_eval &cmds[x.to_sym] else m = Pathname.new x unless (f = found[m]).empty? self.selected = m else raise UsageError, "Unknown command #{x}" end end end end auto_action_file = Pathname.new '/etc/paludis/configs_auto_action' cmds = Commands.new do help 'Help' on %w[\help \?] do puts cmds.list_keys puts end help 'Displays difference of selected file' on '\diff' do raise NoSelection unless selected puts IRB::Pager::pager( pager: 'less -R') { diff selected, found[selected][0] } puts self.need_to_print = false end help 'List all files need updates' on '\list' do list_cfgs selected, list if selected end help 'Accepts selected file' on %w[\accept \yes] do raise NoSelection unless selected accept_cfg selected, found[selected][0] selected = nil end help 'Rejects selected file' on %w[\reject \no] do raise NoSelection unless selected reject_cfg selected, found[selected][0] selected = nil end help 'Ignore selected file for this session (do not anything with this file)' on %w[\later \ignore] do raise NoSelection unless selected ignore_list.push selected self.need_to_print = false self.selected = nil end help 'Quit' on %w[\quit \exit] do exit 0 end on 'auto-action' do unless auto_action_file.exist? raise UsageError, "No config for auto-action found: #{auto_action_file}" end auto_action_file.each_line do |line| next if /^\s*#/ =~ line action, file = line.chomp!.split( "\t", 2) file = Pathname.new file if found.has_key? file case action when *%w[a accept] accept_cfg file, found[file][-1] found[file][0...-1].each {|f| reject_cfg file, f } when *%w[r reject] found[file].each {|f| reject_cfg file, f } end end end end end ui = UI.new cmds, dirs opts = GetoptLong.new( [ '-h', '--help', GetoptLong::NO_ARGUMENT ], [ '-A', '--auto-action', GetoptLong::OPTIONAL_ARGUMENT ] ) opts.ordering = GetoptLong::REQUIRE_ORDER opts.each do |opt, arg| case opt when '-h' puts <