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
36
|
# File 'lib/ppl/command/mv.rb', line 10
def execute(input, output)
old_id = input.arguments.shift
new_id = input.arguments.shift
if old_id.nil?
raise Ppl::Error::IncorrectUsage, "No contact specified"
end
if new_id.nil?
raise Ppl::Error::IncorrectUsage, "No new ID specified"
end
old_contact = @storage.require_contact(old_id)
new_contact = @storage.load_contact(new_id)
if !new_contact.nil?
output.error("There is already a contact with ID '#{new_id}'")
return false
end
@storage.delete_contact(old_contact)
old_contact.id = new_id
@storage.save_contact(old_contact)
return true
end
|