forgitter 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/forgitter +3 -3
- data/lib/forgitter/cli/option_parser.rb +3 -4
- data/lib/forgitter/options.rb +1 -1
- data/lib/forgitter/runner.rb +2 -13
- data/lib/forgitter/types.rb +73 -14
- data/lib/forgitter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d44216e88b2115622aee6a44f918ee7df6f71c7
|
4
|
+
data.tar.gz: eeeca1a668d6ca1750ba9ca0ee3cc8c7fa0d11ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a363100e6e7a990e22a345675d8cb7686fc35f7be3bb1ce25dd1c8109993057b5d60252064e0aa5ee0c9a5749bbea1d287b93722320807a9131f87b87f85d935
|
7
|
+
data.tar.gz: 0e0e10e8ba8404a24fb2f6eabdb92d8ae54d67ae7e6dd1aae5c4586f133be3cd32f2f66372a3f65e0b2d0ffb8a426ef22e4963bb3c1b2a174c82061637c0784f
|
data/bin/forgitter
CHANGED
@@ -6,9 +6,9 @@ require 'forgitter/cli'
|
|
6
6
|
option_parser = Forgitter::CLI::OptionParser.new
|
7
7
|
options = option_parser.parse(ARGV)
|
8
8
|
|
9
|
-
options[:
|
10
|
-
options[:
|
11
|
-
if options[:
|
9
|
+
options[:tags] = []
|
10
|
+
options[:tags] << ARGV.pop until ARGV.empty?
|
11
|
+
if options[:tags].empty?
|
12
12
|
puts option_parser.help
|
13
13
|
exit(1)
|
14
14
|
end
|
@@ -13,15 +13,14 @@ module Forgitter
|
|
13
13
|
@options = Forgitter::DEFAULT_OPTIONS
|
14
14
|
|
15
15
|
@opt_parser = ::OptionParser.new do |opts|
|
16
|
-
opts.banner = 'Usage: forgitter
|
16
|
+
opts.banner = 'Usage: forgitter TAG1 [TAG2 ...]'
|
17
17
|
|
18
18
|
opts.separator ''
|
19
19
|
opts.separator 'Specific options:'
|
20
20
|
|
21
21
|
opts.on('-l', '--list [TAGS]',
|
22
|
-
'List the available types.'
|
23
|
-
|
24
|
-
tags = tags.nil? ? [] : tags.split(',')
|
22
|
+
'List the available types. You may optionally provide a comma-separated list of tags to search for.') do |tags|
|
23
|
+
tags = tags.nil? ? [] : tags.split(',')
|
25
24
|
Forgitter.list_types(tags)
|
26
25
|
exit
|
27
26
|
end
|
data/lib/forgitter/options.rb
CHANGED
data/lib/forgitter/runner.rb
CHANGED
@@ -3,7 +3,7 @@ require 'forgitter'
|
|
3
3
|
module Forgitter
|
4
4
|
class Runner
|
5
5
|
def initialize(options = Forgitter::DEFAULT_OPTIONS)
|
6
|
-
@types =
|
6
|
+
@types = Forgitter.filter_types(options[:tags])
|
7
7
|
@stdout = options[:stdout]
|
8
8
|
end
|
9
9
|
|
@@ -11,7 +11,7 @@ module Forgitter
|
|
11
11
|
failcnt = 0
|
12
12
|
output = ''
|
13
13
|
@types.each do |type|
|
14
|
-
ignore_file = get_ignore_file(type)
|
14
|
+
ignore_file = get_ignore_file(type[:path])
|
15
15
|
if ignore_file
|
16
16
|
output += "# Information from #{type}\n"
|
17
17
|
output += ignore_file
|
@@ -42,16 +42,5 @@ module Forgitter
|
|
42
42
|
false
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
# converts "rails" or "Rails" into "Rails.gitignore"
|
47
|
-
def convert_to_filenames(names)
|
48
|
-
names.map do |name|
|
49
|
-
conversion_table[name.downcase.gsub(/[^+a-z]/i, '')]
|
50
|
-
end.compact
|
51
|
-
end
|
52
|
-
|
53
|
-
def conversion_table
|
54
|
-
Forgitter::TYPES
|
55
|
-
end
|
56
45
|
end
|
57
46
|
end
|
data/lib/forgitter/types.rb
CHANGED
@@ -1,22 +1,83 @@
|
|
1
|
+
require 'debugger'
|
1
2
|
module Forgitter
|
2
|
-
|
3
|
-
|
3
|
+
##
|
4
|
+
# Strip unnecessary characters and downcase the given string.
|
5
|
+
#
|
6
|
+
# @param [String] any string
|
7
|
+
# @return [String] the "parameterized" string
|
8
|
+
#
|
9
|
+
def self.parameterize(str)
|
10
|
+
str.gsub(/[^a-z0-9+]+/i, '').downcase
|
4
11
|
end
|
5
12
|
|
13
|
+
##
|
14
|
+
# Filter types by tags.
|
15
|
+
#
|
16
|
+
# If tags is empty, this will return all types.
|
17
|
+
#
|
18
|
+
# @param [Array] the array of type names and/or tag strings
|
19
|
+
# @return [Array] the array of filtered types
|
20
|
+
#
|
21
|
+
def self.filter_types(tags = [])
|
22
|
+
types.select do |type|
|
23
|
+
tags.empty? || (tags - type[:tags]).empty? || tags.include?(type[:name])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Fetch all available type paths, relative to the DATA_PATH.
|
29
|
+
#
|
30
|
+
# @return [Array] the array of available type paths
|
31
|
+
#
|
32
|
+
def self.paths
|
33
|
+
@@paths ||= Dir["#{DATA_PATH}/**/*.gitignore"].map do |path|
|
34
|
+
path.sub("#{DATA_PATH}/", '')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Pull a parameterized type out of the given path.
|
40
|
+
#
|
41
|
+
# @param [String] the path to a .gitignore file
|
42
|
+
# @return [String] the type
|
43
|
+
#
|
44
|
+
def self.type(path)
|
45
|
+
parameterize(File.basename(path).sub('.gitignore', ''))
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Pull parameterized tags out of the given path.
|
50
|
+
#
|
51
|
+
# If path does not contain a /, this returns an empty array.
|
52
|
+
#
|
53
|
+
# @param [String] the path to a .gitignore file
|
54
|
+
# @return [Array] the tags
|
55
|
+
#
|
56
|
+
def self.tags(path)
|
57
|
+
tags = []
|
58
|
+
if path =~ /\//
|
59
|
+
tags = path.sub("/#{File.basename(path)}", '').split('/')
|
60
|
+
tags.map! do |tag|
|
61
|
+
parameterize(tag)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
tags
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Fetch all available types.
|
69
|
+
#
|
70
|
+
# @return [Array] the array of available types
|
71
|
+
#
|
6
72
|
def self.types
|
7
73
|
unless defined?(@@types) && !@@types.empty?
|
8
74
|
@@types = []
|
9
75
|
|
10
|
-
paths = Dir["#{DATA_PATH}/**/*.gitignore"].map { |f| f.sub("#{DATA_PATH}/", '') }
|
11
76
|
paths.each do |path|
|
12
|
-
type = parameterize(File.basename(path).sub('.gitignore', ''))
|
13
|
-
tags = []
|
14
|
-
tags = path.sub("/#{File.basename(path)}", '').split('/').map { |tag| parameterize(tag) } if path =~ /\//
|
15
|
-
|
16
77
|
@@types << {
|
17
78
|
:path => path,
|
18
|
-
:name => type,
|
19
|
-
:tags => tags
|
79
|
+
:name => type(path),
|
80
|
+
:tags => tags(path)
|
20
81
|
}
|
21
82
|
end
|
22
83
|
end
|
@@ -24,20 +85,18 @@ module Forgitter
|
|
24
85
|
end
|
25
86
|
|
26
87
|
def self.list_types(tags = [])
|
27
|
-
types =
|
28
|
-
|
88
|
+
types = filter_types(tags)
|
29
89
|
if types.empty?
|
30
90
|
puts 'No types found!'
|
31
91
|
else
|
32
92
|
lines = []
|
33
93
|
col1size = 0
|
94
|
+
|
34
95
|
types.each do |type|
|
35
96
|
col1size = type[:name].length if type[:name].length > col1size
|
36
|
-
lines << [type[:name],
|
97
|
+
lines << [type[:name], type[:path]]
|
37
98
|
end
|
38
99
|
|
39
|
-
puts 'Available types:'
|
40
|
-
puts
|
41
100
|
lines.sort_by { |line| line[0] }.each do |line|
|
42
101
|
printf("%-#{col1size}s\t%s\n", line[0], line[1])
|
43
102
|
end
|
data/lib/forgitter/version.rb
CHANGED