#!/usr/bin/env ruby # # Triggers: # ForceRmdir form-in client "ForceRmdir.rb %formfile%" # Options: noallwrite noclobber nocompress unlocked nomodtime rmdir if ARGV.length < 1 puts '%formfile% not given.' exit 1 end opts = [0, 0, 0, 0, 0, 0] for i in 1..ARGV.length-1 do option = ARGV[i] if /.*allwrite/ =~ option opts[0] = option end if /.*clobber/ =~ option opts[1] = option end if /.*compress/ =~ option opts[2] = option end if /.*locked/ =~ option opts[3] = option end if /.*modtime/ =~ option opts[4] = option end if /.*rmdir/ =~ option opts[5] = option end end formfile = ARGV[0] form_string = "" form = File.open(formfile, 'r') form.each do |line| if /^Client:.*p4sandbox-.*$/ =~ line form.close exit 0 elsif /^Options:.*?/ =~ line client_choices = line.gsub(/Options:\s+(.*)/, '\1') client_choices = client_choices.strip.split(/\s+/) options_line = line.gsub(/(Options:\s+).*/, '\1').chomp for i in 0..5 do unless opts[i] == 0 options_line << "#{opts[i]} " else options_line << "#{client_choices[i]} " end end options_line = options_line.strip << "\n" form_string << (options_line) else form_string << (line) end end form.close form = File.open(formfile, 'w') form.write(form_string) form.close exit 0