7
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
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ptf/commands/group/remove.rb', line 7
def remove(group)
if !Ptf::Group.group_exist?(group)
return "Group #{group} does not exist. Add it with ptf group add GROUP ABBREVIATION."
end
group = Ptf::Group.get_group(group)
if group.is_default?
return "#{group.to_s} is the default group. It cannot be removed."
end
puts "Are you sure you want to remove #{group.to_s}? This will delete ALL tasks associated with this group."
confirm = STDIN.gets.chomp
if confirm.downcase != "y" && confirm.downcase != "yes"
return "Group removal aborted."
end
tmp_file = "#{Ptf::FileSystem.group_list_file}.tmp"
File.open(Ptf::FileSystem.group_list_file, "r") do |original|
File.open(tmp_file, "w") do |tmp|
original.each_line do |line|
tmp.write(line) unless line.gsub(/\s+/, "") == group.to_s
end
end
end
File.rename(tmp_file, Ptf::FileSystem.group_list_file)
FileUtils.rm_r File.join(Ptf::FileSystem.metadata_open_dir, group.name)
FileUtils.rm_r File.join(Ptf::FileSystem.metadata_closed_dir, group.name)
return "Group removed."
end
|