gitkeep 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/gitkeep +9 -10
- data/lib/gitkeep.rb +35 -18
- metadata +2 -2
data/bin/gitkeep
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'find'
|
4
3
|
require 'gitkeep'
|
5
4
|
|
6
5
|
gitkeep = Gitkeep.new
|
7
6
|
|
7
|
+
# set options
|
8
|
+
gitkeep.dryrun = !ARGV.delete('-d').nil?
|
9
|
+
gitkeep.interactive = !ARGV.delete('-i').nil?
|
10
|
+
|
8
11
|
if ARGV.size == 0
|
9
|
-
|
12
|
+
# no options, create in current path
|
13
|
+
gitkeep.create(".")
|
10
14
|
else
|
11
|
-
|
12
|
-
|
13
|
-
gitkeep.create(
|
14
|
-
else
|
15
|
-
ARGV.sort.each do |arg|
|
16
|
-
gitkeep.dryrun = true if arg == "-d"
|
17
|
-
gitkeep.create(arg) unless arg =~ /^-+/
|
18
|
-
end
|
15
|
+
# iterate over paths
|
16
|
+
ARGV.each do |arg|
|
17
|
+
gitkeep.create(arg) unless arg =~ /^-+/
|
19
18
|
end
|
20
19
|
end
|
data/lib/gitkeep.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
1
3
|
class Gitkeep
|
2
4
|
|
3
|
-
attr_accessor :dryrun
|
5
|
+
attr_accessor :dryrun, :interactive, :__test
|
6
|
+
attr_reader :file_count, :error_count
|
4
7
|
|
5
8
|
def initialize
|
9
|
+
@__test = false
|
6
10
|
@dryrun = false
|
7
|
-
@
|
11
|
+
@interactive = false
|
12
|
+
@file_count = 0
|
13
|
+
@error_count = 0
|
8
14
|
end
|
9
15
|
|
10
16
|
def create(path)
|
11
17
|
path = "." if path.empty?
|
12
18
|
|
13
19
|
unless File.directory?(path)
|
14
|
-
puts "error
|
20
|
+
puts red("[error] directory \"#{path}\" not found! abort...")
|
15
21
|
return false
|
16
22
|
end
|
17
23
|
|
@@ -27,43 +33,54 @@ class Gitkeep
|
|
27
33
|
Find.prune
|
28
34
|
else
|
29
35
|
if Dir.entries(p).size == 2
|
30
|
-
|
36
|
+
save(p)
|
31
37
|
end
|
32
38
|
end
|
33
39
|
else
|
34
40
|
puts red("[error] could not READ in #{p}/ -> check permissions")
|
41
|
+
@error_count += 1
|
35
42
|
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
39
|
-
puts "finished. #{@
|
46
|
+
puts "finished. #{@file_count} file(s) created!"
|
47
|
+
puts red("#{@error_count} error(s)...") if @error_count > 0
|
48
|
+
true if @error_count == 0
|
40
49
|
end
|
41
50
|
|
42
|
-
protected
|
51
|
+
protected if @__test == false
|
43
52
|
|
44
|
-
def
|
53
|
+
def save(path)
|
45
54
|
gitkeep = "#{path}/.gitkeep"
|
46
55
|
|
47
56
|
unless File.writable?(path)
|
48
57
|
puts red("[error] could not WRITE in #{path}/ -> check permissions")
|
58
|
+
@error_count += 1
|
49
59
|
return false
|
50
60
|
end
|
51
61
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
puts blue("[dryrun] created #{gitkeep}")
|
59
|
-
end
|
62
|
+
return true if File.exists?(gitkeep)
|
63
|
+
|
64
|
+
if @interactive
|
65
|
+
print "create #{gitkeep} ? [Yn]"
|
66
|
+
a = $stdin.gets # read from stdin to avoid collision with params ARGV
|
67
|
+
return false unless a == "\n" || a.downcase == "y\n"
|
60
68
|
end
|
61
69
|
|
62
|
-
@
|
63
|
-
|
70
|
+
@file_count += 1
|
71
|
+
|
72
|
+
unless @dryrun
|
73
|
+
f = File.new(gitkeep, "w+")
|
74
|
+
f.close
|
75
|
+
puts green("created #{gitkeep}")
|
76
|
+
true
|
77
|
+
else
|
78
|
+
puts blue("[dryrun] created #{gitkeep}")
|
79
|
+
nil
|
80
|
+
end
|
64
81
|
end
|
65
82
|
|
66
|
-
private
|
83
|
+
private if @__test == false
|
67
84
|
|
68
85
|
def colorize(text, color_code)
|
69
86
|
"\e[#{color_code}m#{text}\e[0m"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitkeep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: create .gitkeep files in all empty directories in your project
|
15
15
|
email: arthurz.mobile@gmail.com
|