Class: P4Tools::Move
- Inherits:
-
Object
- Object
- P4Tools::Move
- Defined in:
- lib/commands/move.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_workspace(changelist_spec) ⇒ Object
-
#initialize(args) ⇒ Move
constructor
A new instance of Move.
- #move_changelists ⇒ Object
- #prepare_workspaces ⇒ Object
- #revert ⇒ Object
- #run ⇒ Object
- #shelve ⇒ Object
- #validate_current(current_workspace) ⇒ Object
- #validate_workspaces(workspaces) ⇒ Object
Constructor Details
#initialize(args) ⇒ Move
Returns a new instance of Move.
24 25 26 27 28 29 30 31 32 |
# File 'lib/commands/move.rb', line 24 def initialize(args) @workspace = args[:workspace] @switch = args[:switch] @changelists = args[:changelists] @revert = args[:revert] @shelve = args[:shelve] @p4 = P4Tools.connection end |
Class Method Details
.run(arguments) ⇒ Object
4 5 6 |
# File 'lib/commands/move.rb', line 4 def self.run(arguments) Move.new(arguments).run end |
.set_options(opts) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/commands/move.rb', line 8 def self.(opts) opts.set do help 'Move a pending changelist from one workspace to another, optionally shelve and delete them before.' help 'The changelist need to be empty to move(only shelved files allowed)!' help '' help 'Options:' help '' arg :workspace, "Name of the new workspace. If 'switch' option provided, this will be ignored.", :short => '-w', :type => :string arg :switch, 'Switch between workspaces, only 2 workspace name allowed.', :short => '-i', :type => :strings arg :changelists, 'Changelist numbers to move.', :short => '-c', :type => :ints, :required => true arg :revert, 'Revert before move.', :short => '-r' arg :shelve, 'Shelve before move.', :short => '-s' end end |
Instance Method Details
#get_workspace(changelist_spec) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/commands/move.rb', line 73 def get_workspace(changelist_spec) if @workspaces current = changelist_spec['Client'] validate_current(current) @workspaces[current] else @workspace end end |
#move_changelists ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/commands/move.rb', line 47 def move_changelists @changelists.each do |changelist| @changelist = changelist @is_not_empty = !CommandUtils.empty_changelist?(@changelist) shelve revert changelist_spec = @p4.fetch_change(@changelist) changelist_spec['Client'] = get_workspace(changelist_spec) @p4.save_change(changelist_spec) end end |
#prepare_workspaces ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/commands/move.rb', line 39 def prepare_workspaces if @switch validate_workspaces(@switch) @workspaces = Hash[@switch.permutation.to_a] end end |
#revert ⇒ Object
67 68 69 70 71 |
# File 'lib/commands/move.rb', line 67 def revert if @revert && @is_not_empty && CommandUtils.changelist_shelved?(@changelist) @p4.run_revert('-w', '-c', @changelist, '//...') end end |
#run ⇒ Object
34 35 36 37 |
# File 'lib/commands/move.rb', line 34 def run prepare_workspaces move_changelists end |
#shelve ⇒ Object
61 62 63 64 65 |
# File 'lib/commands/move.rb', line 61 def shelve if @shelve && @is_not_empty @p4.run_shelve('-f', '-c', @changelist) end end |
#validate_current(current_workspace) ⇒ Object
84 85 86 87 88 |
# File 'lib/commands/move.rb', line 84 def validate_current(current_workspace) unless @workspaces.include?(current_workspace) raise(ArgumentError, "The switch parameter does not contains the currently active workspace: #{current_workspace}!") end end |
#validate_workspaces(workspaces) ⇒ Object
90 91 92 93 94 |
# File 'lib/commands/move.rb', line 90 def validate_workspaces(workspaces) if workspaces.length != 2 raise(ArgumentError, 'The switch parameter need to contains 2 workspace names exactly!') end end |