Class: P4Tools::Revert

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/revert.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Revert

Returns a new instance of Revert.



22
23
24
25
26
27
28
29
# File 'lib/commands/revert.rb', line 22

def initialize(args)
  @delete_added_files = args[:delete_added_files]
  @check_shelve = args[:check_shelve]
  @changelists = args[:changelists]
  @files = args[:files]

  @p4 = P4Tools.connection
end

Class Method Details

.run(arguments) ⇒ Object



4
5
6
# File 'lib/commands/revert.rb', line 4

def self.run(arguments)
  Revert.new(arguments).run
end

.set_options(opts) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/commands/revert.rb', line 8

def self.set_options(opts)
  opts.set do
    help 'Revert the given files or all file in the changelist and optionally delete the added files from the disk too.'
    help ''
    help 'Options:'
    help ''
    arg :delete_added_files, 'Delete added files.', :short => '-d'
    arg :check_shelve, 'Check if all files shelved, before revert them.', :short => '-s'
    arg :changelists, 'Changelist numbers.', :short => '-c', :type => :ints
    arg :files, 'The absolute path of the files to delete.', :short => '-f', :type => :strings
  end
end

Instance Method Details

#check_shelved_changelist(changelist) ⇒ Object



63
64
65
66
67
# File 'lib/commands/revert.rb', line 63

def check_shelved_changelist(changelist)
  if @check_shelve && !CommandUtils.changelist_shelved?(changelist)
    raise(StandardError, "Not all files are shelved in changelist: #{changelist}")
  end
end

#check_shelved_files(files) ⇒ Object



69
70
71
72
73
# File 'lib/commands/revert.rb', line 69

def check_shelved_files(files)
  if @check_shelve && !CommandUtils.files_shelved?(files)
    raise(StandardError, "Not all files are shelved from list: #{files}")
  end
end

#revert_changelistsObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/commands/revert.rb', line 51

def revert_changelists
  @changelists.each do |changelist|
    check_shelved_changelist(changelist)

    if @delete_added_files
      @p4.run_revert('-w', '-c', changelist, '//...')
    else
      @p4.run_revert('-c', changelist, '//...')
    end
  end
end

#revert_filesObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/commands/revert.rb', line 39

def revert_files
  check_shelved_files(@files)

  parameters = []
  if @delete_added_files
    parameters.push('-w')
  end

  parameters.push(*@files)
  @p4.run_revert(parameters)
end

#runObject



31
32
33
34
35
36
37
# File 'lib/commands/revert.rb', line 31

def run
  if !@changelists.nil?
    revert_changelists
  elsif !@files.nil?
    revert_files
  end
end