pullall 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pullall.rb +1 -1
- data/lib/pullall/actions.rb +17 -5
- metadata +1 -1
data/lib/pullall.rb
CHANGED
data/lib/pullall/actions.rb
CHANGED
@@ -4,6 +4,16 @@ module Actions
|
|
4
4
|
|
5
5
|
STORAGE = "#{ENV['HOME']}/.pullall"
|
6
6
|
|
7
|
+
# Output in red
|
8
|
+
def colorize(text)
|
9
|
+
"\e[#{31}m#{text}\e[0m"
|
10
|
+
end
|
11
|
+
|
12
|
+
def pluralize(n, text)
|
13
|
+
(n == 1) ? text : "#{text}s"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Use real path to allow the use of .(current directory) as an argument
|
7
17
|
def get_real_paths(paths)
|
8
18
|
paths.collect! do |path|
|
9
19
|
if File.exists?(path)
|
@@ -15,11 +25,12 @@ module Actions
|
|
15
25
|
paths
|
16
26
|
end
|
17
27
|
|
28
|
+
# Output all the groups and associated paths
|
18
29
|
def list_groups
|
19
30
|
groups = load_all
|
20
31
|
puts "\n"
|
21
32
|
groups.each do |group, paths|
|
22
|
-
puts "#{group}
|
33
|
+
puts "#{colorize(group)}: #{paths.join(', ')}"
|
23
34
|
puts "\n"
|
24
35
|
end
|
25
36
|
end
|
@@ -29,10 +40,10 @@ module Actions
|
|
29
40
|
Oj.to_file(STORAGE, json)
|
30
41
|
end
|
31
42
|
|
43
|
+
# Only allow saving a path or a group of paths if all of them don't belong to the group
|
32
44
|
def save_paths(*paths, group)
|
33
45
|
groups = load_all
|
34
46
|
|
35
|
-
# Use real path to allow the use of .(current directory) as an argument
|
36
47
|
if groups.has_key?(group)
|
37
48
|
paths.each do |path|
|
38
49
|
if groups[group].include?(path)
|
@@ -44,10 +55,11 @@ module Actions
|
|
44
55
|
groups[group] = [*paths]
|
45
56
|
end
|
46
57
|
save_all(groups)
|
47
|
-
msg = paths.empty? ? "Group successfully created" : "
|
58
|
+
msg = paths.empty? ? "Group successfully created" : "#{pluralize(paths.size, "Path")} successfully saved"
|
48
59
|
puts msg
|
49
60
|
end
|
50
61
|
|
62
|
+
# Get the paths that belong to a given group
|
51
63
|
def load_paths(group)
|
52
64
|
groups = load_all
|
53
65
|
if groups.has_key?(group)
|
@@ -96,7 +108,7 @@ module Actions
|
|
96
108
|
end
|
97
109
|
end
|
98
110
|
save_all(groups)
|
99
|
-
puts "Paths successfully removed from group #{group}"
|
111
|
+
puts "Paths successfully removed from group #{colorize(group)}"
|
100
112
|
else
|
101
113
|
Trollop::die "Group #{group} doesn't exist"
|
102
114
|
end
|
@@ -105,7 +117,7 @@ module Actions
|
|
105
117
|
def pull(group)
|
106
118
|
paths = load_paths(group)
|
107
119
|
paths.each do |path|
|
108
|
-
puts "Pulling from #{path}:"
|
120
|
+
puts "Pulling from #{colorize(path)}:"
|
109
121
|
%x(git --git-dir #{path}/.git pull origin master)
|
110
122
|
puts "\n"
|
111
123
|
end
|