Sha256: 6d25ea64a00ee5ca54556f993f34b435f8af2711d90d2b130e04af83dfdff092
Contents?: true
Size: 1.74 KB
Versions: 2
Compression:
Stored size: 1.74 KB
Contents
require 'conventions' require 'random_util' module Commands module Init module P4Helpers # Intended to be a block helper that creates a 'temporary client' # # Your block should take the client name and path. # # Example: # # open_client(p4) do |path, name| # puts "my client #{name}'s root is #{path}" # end def open_client(options) p4 = options[:p4] # Switch user only if specified user = nil password = nil olduser = nil oldpass = nil if (options[:user]) user = options[:user] password = options[:password] if options.key?(:password) olduser = options[:olduser] oldpass = options[:oldpass] if options.key?(:oldpass) p4.user = user p4.password = password p4.run_login if password end name = RandomUtil.randstr dir = File.join(Conventions.client_root_dir, name) if !Dir.exist?(dir) FileUtils.mkpath(dir) end spec = p4.fetch_client spec._root = dir spec._client = name spec._description = 'p4util init temp client' spec._view = ["//depot/... //#{name}/depot/..."] p4.save_client(spec) p4.client = name p4.run_sync('-f', '//...') if block_given? yield dir, name else return dir, name end ensure if block_given? if (user) p4.user = olduser p4.password = oldpass p4.run_login if oldpass end p4.run_client('-d', '-f', name) p4.client = 'invalid' FileUtils.rmtree(dir) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
p4util-0.1.1 | ./lib/commands/init/p4_helpers.rb |
p4util-0.1.0 | ./lib/commands/init/p4_helpers.rb |