Module: Commands

Defined in:
lib/commands/help.rb,
lib/commands/kill.rb,
lib/commands/start.rb,
lib/commands/download.rb

Class Method Summary collapse

Class Method Details

.download(options = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/commands/download.rb', line 8

def Commands.download(options=nil)
  version = 'r14.2'
  binary = 'p4d'

  if options and !options.params.empty?

    op = OptionParser.new do |op|
      op.on('-v VERSION', '--version VERSION', 'ftp.perforce.com version') do |v|
        version = v
      end
    end

    op.parse!(options.params)

    if !options.params.empty?
      binary = options.params.first
    end
  end

  case binary
    when 'p4d'
      download_p4d_via_ftp(version)
    when 'p4api'
      download_p4api_via_ftp(version)
    else
      raise "Don't know how to download #{binary}, check 'p4util help download'"
  end
end

.help(options) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/commands/help.rb', line 4

def Commands.help(options)
  if !options.params.empty? && Commands.respond_to?(options.params.first.to_sym)
    method_name = "print_#{options.params.first}_help".to_sym
    Commands.method(method_name).call()
  else
    print_general_help
  end
end

.kill(options = nil) ⇒ Object



7
8
9
10
# File 'lib/commands/kill.rb', line 7

def Commands.kill(options=nil)
  ProcTable.ps().find_all{|p| p.comm =~ /p4d/}
                .each{|p| Process.kill('TERM', p.pid)}
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/commands/download.rb', line 37

def Commands.print_download_help
  puts <<-END.gsub(/^ {6}/, '')
    p4util download [p4d|p4api]

    Downloads one of the following utilities (in lieu of an installer) into
    a local work/ directory.

    * p4d
    * p4api

    Will default to the latest release unless you don't know what that is.

    Options:

    --version X where X looks like the version in the ftp.perforce.com site,
              e.g., 'r14.2' instead of '2014.2'
  END
end


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/commands/kill.rb', line 12

def Commands.print_kill_help
  puts <<-END.gsub(/^ {6}/,'')
    p4util kill

    Finds local p4d processes and kills them.

    There should be a timeout that will force kill anything that appears stuck.

    On unix machines, will probably use `ps -x` and 'p4d', then will send
    SIGTERM signals to each process.
  END
end


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/commands/start.rb', line 18

def Commands.print_start_help
  puts <<-END.gsub(/^ {6}/,'')
    p4util start

    Spawns a Perforce process in your local work/p4droot directory.

    If the Perforce executable does not exist, will download the binary first.

    Will try to set up a server log at work/server.log. It'll be fairly
    verbose by default; this is *not* intended for any kind of performance
    testing.
  END
end

.spawn_p4dObject



12
13
14
15
16
# File 'lib/commands/start.rb', line 12

def Commands.spawn_p4d
  pid = Process.spawn("#{OsUtil.p4d_path} -r #{Conventions.p4droot_dir} "+
                      "-v server=1 -L #{Conventions.p4d_log_path}")
  Process.detach(pid)
end

.start(options) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/commands/start.rb', line 4

def Commands.start(options)
  if !File.exists?(OsUtil.p4d_path)
    Commands.download
  end
  Conventions.init_p4droot_dir
  spawn_p4d
end