gemignore 0.1.1 → 0.2.0
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/Changelog +8 -0
- data/Gemfile +1 -0
- data/README.rdoc +6 -2
- data/VERSION +1 -1
- data/gemignore.gemspec +73 -0
- data/lib/gemignore/main.rb +68 -25
- data/lib/gemignore/util.rb +24 -0
- metadata +31 -13
data/Changelog
ADDED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -6,16 +6,20 @@ This is a handy little tool for all people who work with Git. It allows you to e
|
|
6
6
|
|
7
7
|
To search for a .gitignore snippet, simply type
|
8
8
|
|
9
|
-
$ gemignore searchword
|
9
|
+
$ gemignore search searchword
|
10
10
|
|
11
11
|
To list all available snippets run
|
12
12
|
|
13
|
-
$ gemignore
|
13
|
+
$ gemignore list
|
14
14
|
|
15
15
|
And finally, to add a snippet to the .gitignore file in the <b>current working directory</b>:
|
16
16
|
|
17
17
|
$ gemignore add Global/OSX
|
18
18
|
|
19
|
+
To display usage information you can use
|
20
|
+
|
21
|
+
$ gemignore help
|
22
|
+
|
19
23
|
== Copyright
|
20
24
|
|
21
25
|
Copyright (c) 2011 Lucas Jenß. See LICENSE.txt for
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/gemignore.gemspec
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{gemignore}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Lucas Jenss"]
|
12
|
+
s.date = %q{2011-05-28}
|
13
|
+
s.default_executable = %q{gemignore}
|
14
|
+
s.description = %q{gemignore allows you to automatically insert a wide range of preset .gitignore snippets into your .gitignore files}
|
15
|
+
s.email = %q{lucas@x3ro.de}
|
16
|
+
s.executables = ["gemignore"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Changelog",
|
25
|
+
"Gemfile",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"bin/.gitignore",
|
31
|
+
"bin/gemignore",
|
32
|
+
"gemignore.gemspec",
|
33
|
+
"lib/gemignore.rb",
|
34
|
+
"lib/gemignore/main.rb",
|
35
|
+
"lib/gemignore/util.rb",
|
36
|
+
"spec/gemignore_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/x3ro/gemignore}
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
|
+
s.summary = %q{A command-line tool which ought to simplify your daily .gitignore hassle}
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<json>, [">= 1.5.1"])
|
51
|
+
s.add_runtime_dependency(%q<rainbow>, ["~> 1.1.1"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<json>, [">= 1.5.1"])
|
58
|
+
s.add_dependency(%q<rainbow>, ["~> 1.1.1"])
|
59
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
62
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<json>, [">= 1.5.1"])
|
66
|
+
s.add_dependency(%q<rainbow>, ["~> 1.1.1"])
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/lib/gemignore/main.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rainbow'
|
1
3
|
require 'net/http'
|
2
4
|
require 'net/https'
|
3
5
|
require 'json'
|
4
|
-
require 'pp'
|
5
6
|
|
7
|
+
require 'gemignore/util'
|
6
8
|
|
7
9
|
module GemIgnore
|
8
10
|
|
@@ -13,25 +15,62 @@ module GemIgnore
|
|
13
15
|
#++
|
14
16
|
class Main
|
15
17
|
|
18
|
+
include Util
|
19
|
+
|
16
20
|
def dispatch
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
|
22
|
+
(help; return) if ARGV.length === 0
|
23
|
+
|
24
|
+
cmd = ARGV.shift # get the sub-command
|
25
|
+
case cmd
|
26
|
+
when "list"
|
27
|
+
list
|
28
|
+
when "search"
|
29
|
+
search
|
30
|
+
when "add"
|
31
|
+
add
|
32
|
+
when "help"
|
33
|
+
help
|
34
|
+
else
|
35
|
+
error "Unknown gemignore command '#{cmd}'."
|
36
|
+
notice "Run 'gemignore help' to display usage information."
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
# Displays some usage information
|
42
|
+
def help
|
43
|
+
notice <<-BANNER
|
44
|
+
gemignore - .gitignore snippet utility
|
45
|
+
usage: gemignore <command> <input>
|
46
|
+
|
47
|
+
Available commands are:
|
48
|
+
list Lists all available snippets
|
49
|
+
search Searches for snippets containing <input>
|
50
|
+
add Add a snippet to the .gitignore file in your working directory
|
51
|
+
help Display this message
|
52
|
+
BANNER
|
20
53
|
end
|
21
54
|
|
22
55
|
# Displays a list of available .gitignore snippets
|
23
56
|
def list
|
24
|
-
|
57
|
+
msg "Available .gitignore snippets:", 1
|
25
58
|
fetch().each do |f|
|
26
|
-
|
59
|
+
notice f, 2
|
27
60
|
end
|
28
61
|
end
|
29
62
|
|
30
63
|
# Searches for a given snippet name
|
31
64
|
def search
|
32
|
-
|
33
|
-
|
34
|
-
|
65
|
+
results = fetch(ARGV[0])
|
66
|
+
if(results.length < 1)
|
67
|
+
error "No snippets found for '#{ARGV[0]}'", 1
|
68
|
+
else
|
69
|
+
msg "Snippets found for '#{ARGV[0]}':", 1
|
70
|
+
results.each do |f|
|
71
|
+
notice f, 2
|
72
|
+
end
|
73
|
+
|
35
74
|
end
|
36
75
|
end
|
37
76
|
|
@@ -39,13 +78,14 @@ module GemIgnore
|
|
39
78
|
# directory in case it exists and the given snippet identifier matched
|
40
79
|
# exactly one snippet.
|
41
80
|
def add
|
42
|
-
snippets = fetch(
|
81
|
+
snippets = fetch(ARGV[0])
|
43
82
|
if snippets.length < 1
|
44
|
-
|
83
|
+
error "No snippets found for '#{ARGV[0]}'", 1
|
45
84
|
elsif snippets.length > 1
|
46
|
-
|
85
|
+
error "Multiple possible snippets found for '#{ARGV[0]}'.", 1
|
86
|
+
error "Please be more specific.", 1
|
47
87
|
snippets.each do |f|
|
48
|
-
|
88
|
+
notice f, 2
|
49
89
|
end
|
50
90
|
else
|
51
91
|
performAdd(snippets.first)
|
@@ -55,24 +95,28 @@ module GemIgnore
|
|
55
95
|
# Adds the given snippet in case the .gitignore file exists.
|
56
96
|
def performAdd(snippet)
|
57
97
|
if not File.exists?(".gitignore")
|
58
|
-
|
98
|
+
error "No .gitignore file found in working directory.", 1
|
59
99
|
else
|
60
|
-
|
61
|
-
puts "Adding Snippet '#{snippet}'"
|
100
|
+
notice "Adding Snippet '#{snippet}'.", 1
|
62
101
|
|
63
102
|
f = File.new(".gitignore", "a")
|
64
103
|
snippetData = fetchFile(snippet)
|
65
104
|
f.write("\n\n# Added by gemignore. Snippet '#{snippet}'\n" + snippetData)
|
66
105
|
f.close
|
106
|
+
|
107
|
+
msg "Successfully added snippet.", 1
|
67
108
|
end
|
68
109
|
end
|
69
110
|
|
70
|
-
# Creates a
|
111
|
+
# Creates a Regexp for the given string. Will be case-insensitive if the
|
112
|
+
# input does not contain any uppercase characters. Wildcards are
|
71
113
|
# added before and after the input, so the regex will match anything containing
|
72
114
|
# the input, or the input itself.
|
73
115
|
def regexpForInput(input)
|
116
|
+
return (/(.*)/) if not input
|
74
117
|
input = Regexp.escape(input)
|
75
|
-
|
118
|
+
opt = input =~ /[A-Z]/ ? nil : Regexp::IGNORECASE;
|
119
|
+
Regexp.new("(.*#{input}.*)", opt)
|
76
120
|
end
|
77
121
|
|
78
122
|
# Fetches the list of available snippets via the GitHub API
|
@@ -80,11 +124,10 @@ module GemIgnore
|
|
80
124
|
# FIXME: Do some (url) refactoring
|
81
125
|
#++
|
82
126
|
def fetch(search = nil)
|
83
|
-
search =
|
84
|
-
|
127
|
+
search = regexpForInput(search)
|
85
128
|
data = Net::HTTP.get( URI.parse('http://github.com/api/v2/json/blob/all/github/gitignore/master') )
|
86
129
|
response = JSON.parse(data)
|
87
|
-
files = response["blobs"].map { |k,v| k.split('.
|
130
|
+
files = response["blobs"].map { |k,v| t = k.split('.'); (t[0] =~ search; $1) if t.last === 'gitignore' }
|
88
131
|
files.compact
|
89
132
|
end
|
90
133
|
|
@@ -99,11 +142,11 @@ module GemIgnore
|
|
99
142
|
http.use_ssl = true if url.scheme == "https" # enable SSL/TLS
|
100
143
|
|
101
144
|
data = ""
|
102
|
-
http.start
|
103
|
-
http.request_get(url.path)
|
145
|
+
http.start do
|
146
|
+
http.request_get(url.path) do |res|
|
104
147
|
data = res.body
|
105
|
-
|
106
|
-
|
148
|
+
end
|
149
|
+
end
|
107
150
|
|
108
151
|
data
|
109
152
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GemIgnore
|
2
|
+
module Util
|
3
|
+
|
4
|
+
def msg(msg, level=0)
|
5
|
+
puts (prefix(level) + msg).foreground(:green)
|
6
|
+
end
|
7
|
+
|
8
|
+
def notice(msg, level=0)
|
9
|
+
puts (prefix(level) + msg).foreground(:yellow)
|
10
|
+
end
|
11
|
+
|
12
|
+
def error(msg, level=0)
|
13
|
+
puts (prefix(level) + msg).foreground(:red)
|
14
|
+
end
|
15
|
+
|
16
|
+
def prefix(level)
|
17
|
+
return "" if level <= 0
|
18
|
+
("-" * level) + "> "
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Lucas Jenss
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-05-
|
17
|
+
date: 2011-05-28 00:00:00 +02:00
|
18
18
|
default_executable: gemignore
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -33,8 +33,23 @@ dependencies:
|
|
33
33
|
prerelease: false
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: rainbow
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 1
|
45
|
+
- 1
|
46
|
+
version: 1.1.1
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
53
|
none: false
|
39
54
|
requirements:
|
40
55
|
- - ~>
|
@@ -46,10 +61,10 @@ dependencies:
|
|
46
61
|
version: 2.3.0
|
47
62
|
type: :development
|
48
63
|
prerelease: false
|
49
|
-
version_requirements: *
|
64
|
+
version_requirements: *id003
|
50
65
|
- !ruby/object:Gem::Dependency
|
51
66
|
name: bundler
|
52
|
-
requirement: &
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
68
|
none: false
|
54
69
|
requirements:
|
55
70
|
- - ~>
|
@@ -61,10 +76,10 @@ dependencies:
|
|
61
76
|
version: 1.0.0
|
62
77
|
type: :development
|
63
78
|
prerelease: false
|
64
|
-
version_requirements: *
|
79
|
+
version_requirements: *id004
|
65
80
|
- !ruby/object:Gem::Dependency
|
66
81
|
name: jeweler
|
67
|
-
requirement: &
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
68
83
|
none: false
|
69
84
|
requirements:
|
70
85
|
- - ~>
|
@@ -76,10 +91,10 @@ dependencies:
|
|
76
91
|
version: 1.6.0
|
77
92
|
type: :development
|
78
93
|
prerelease: false
|
79
|
-
version_requirements: *
|
94
|
+
version_requirements: *id005
|
80
95
|
- !ruby/object:Gem::Dependency
|
81
96
|
name: rcov
|
82
|
-
requirement: &
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
83
98
|
none: false
|
84
99
|
requirements:
|
85
100
|
- - ">="
|
@@ -89,7 +104,7 @@ dependencies:
|
|
89
104
|
version: "0"
|
90
105
|
type: :development
|
91
106
|
prerelease: false
|
92
|
-
version_requirements: *
|
107
|
+
version_requirements: *id006
|
93
108
|
description: gemignore allows you to automatically insert a wide range of preset .gitignore snippets into your .gitignore files
|
94
109
|
email: lucas@x3ro.de
|
95
110
|
executables:
|
@@ -102,6 +117,7 @@ extra_rdoc_files:
|
|
102
117
|
files:
|
103
118
|
- .document
|
104
119
|
- .rspec
|
120
|
+
- Changelog
|
105
121
|
- Gemfile
|
106
122
|
- LICENSE.txt
|
107
123
|
- README.rdoc
|
@@ -109,8 +125,10 @@ files:
|
|
109
125
|
- VERSION
|
110
126
|
- bin/.gitignore
|
111
127
|
- bin/gemignore
|
128
|
+
- gemignore.gemspec
|
112
129
|
- lib/gemignore.rb
|
113
130
|
- lib/gemignore/main.rb
|
131
|
+
- lib/gemignore/util.rb
|
114
132
|
- spec/gemignore_spec.rb
|
115
133
|
- spec/spec_helper.rb
|
116
134
|
has_rdoc: true
|
@@ -127,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
145
|
requirements:
|
128
146
|
- - ">="
|
129
147
|
- !ruby/object:Gem::Version
|
130
|
-
hash:
|
148
|
+
hash: 1748015699591437022
|
131
149
|
segments:
|
132
150
|
- 0
|
133
151
|
version: "0"
|