check_names 0.3.0 → 0.5.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.
- checksums.yaml +4 -4
- data/exe/check_names +49 -48
- data/lib/check_names/version.rb +1 -1
- data/lib/check_names.rb +24 -46
- data/sig/check_names.rbs +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bab692e352dc013e789d94d727cdc70520b1bf58a6ec2547dc770f94956e086
|
4
|
+
data.tar.gz: 8f753e604b1ceca688e5205ef9b4c55e17bbead39f3b2c3484038ae38fcd9b30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6eba30abc087cbf322224c1d689df2b3ed234252b3ac7e239b66046f20c45c62d9736961c6ba257ab054e49fc74c6c1ac7581de3aef23075ba8bc6bd2f89d5d
|
7
|
+
data.tar.gz: 51318e1543af9c775d589a6b5bdb401eb8383a3e74b8a4413a6d2ba073fe093403de878adde1627ce86e4ac415024279573bfb625f888d9ce2e36fdc2bf2869f
|
data/exe/check_names
CHANGED
@@ -11,75 +11,76 @@
|
|
11
11
|
# 4. Does an alias with this name already exist?
|
12
12
|
# 5. Does a function with this name already exist?
|
13
13
|
|
14
|
+
require 'optimist'
|
14
15
|
require_relative '../lib/check_names/version'
|
15
16
|
require_relative '../lib/check_names'
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
BANNER = <<-BANNER_TEXT
|
19
|
+
#{File.basename(__FILE__)}:
|
20
|
+
ersion #{CheckNames.version}
|
21
|
+
|
22
|
+
Check whether a proposed gem name already exists
|
21
23
|
|
22
24
|
Usage:
|
23
|
-
|
25
|
+
#{File.basename(__FILE__)} OPTIONS NAME...
|
24
26
|
|
25
|
-
check_names exits with a zero return code (success) if no conflicting gem
|
26
|
-
name exists. Otherwise it exits with a non-zero return code, with one
|
27
|
-
of the following meanings:
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
5 You have an alias with this name
|
34
|
-
6 This name is used by a Ruby standard class
|
28
|
+
check_names looks to see whether the names provided are already in use.
|
29
|
+
It outputs the usage (if any) of each name on $STDOUT. It exits with a
|
30
|
+
zero return code if none of the names are already in use. Otherwise it
|
31
|
+
exits with return code 1.
|
35
32
|
|
36
|
-
|
37
|
-
received for any name.
|
33
|
+
check_names checks for each of the following uses:
|
38
34
|
|
39
|
-
The
|
35
|
+
- The name of a Ruby standard class
|
36
|
+
- The name of a gem on RubyGems
|
37
|
+
- The name of one of your Github repositories
|
38
|
+
- The name of a sehll alias
|
39
|
+
- The name of a shell function
|
40
|
+
- The name of an executable (reachable via \$PATH)
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
The following options are allowed:
|
43
|
+
BANNER_TEXT
|
44
|
+
|
45
|
+
def main
|
46
|
+
opts = Optimist.options do
|
47
|
+
version CheckNames.version
|
48
|
+
banner BANNER
|
49
|
+
opt :all, "Check for all possible uses. (Default is to stop at the first one found.)", default: false
|
50
|
+
educate_on_error
|
51
|
+
end
|
47
52
|
|
48
|
-
|
53
|
+
all = opts[:all]
|
54
|
+
args = ARGV
|
49
55
|
args = args.map { |arg| arg.downcase }
|
50
|
-
|
51
|
-
args.
|
52
|
-
|
53
|
-
args.delete_at(all) if all
|
54
|
-
if args.size == 0 || %w{-h --help help}.include?(args.first)
|
55
|
-
show_help
|
56
|
+
|
57
|
+
if args.size == 0
|
58
|
+
Optimist.educate
|
56
59
|
exit
|
57
60
|
end
|
58
61
|
|
59
|
-
if all
|
60
|
-
results = GemName.check_names_all(*args)
|
61
|
-
else
|
62
|
-
results = GemName.check_names(*args)
|
63
|
-
end
|
64
|
-
|
65
62
|
rc = 0
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
63
|
+
args.each.with_index(0) do |arg, i|
|
64
|
+
print "#{arg}: "
|
65
|
+
checks_printed_count = 0
|
66
|
+
(1...(CheckNames.check_methods.size)).each do |check|
|
67
|
+
result = CheckNames.check_name(check, arg)
|
68
|
+
if result[:result]
|
69
|
+
print ", " if checks_printed_count > 0
|
70
|
+
print result[:description]
|
71
|
+
checks_printed_count += 1
|
72
|
+
end
|
73
|
+
if checks_printed_count > 0
|
74
|
+
rc = 1
|
75
|
+
break unless all
|
75
76
|
end
|
76
|
-
types = []
|
77
77
|
end
|
78
|
+
print CheckNames.check_method(0)[:description] unless checks_printed_count > 0
|
79
|
+
puts
|
78
80
|
end
|
79
|
-
rc = 1 if rc > 0 && (all || args.size > 1)
|
80
81
|
exit(rc)
|
81
82
|
end
|
82
83
|
|
83
84
|
if __FILE__ == $0
|
84
|
-
main
|
85
|
+
main
|
85
86
|
end
|
data/lib/check_names/version.rb
CHANGED
data/lib/check_names.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative "check_names/version"
|
|
4
4
|
require 'shellwords'
|
5
5
|
require 'httparty'
|
6
6
|
|
7
|
-
module
|
7
|
+
module CheckNames
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
10
|
def self.ruby_gem_exists?(name)
|
@@ -48,24 +48,38 @@ module GemName
|
|
48
48
|
|
49
49
|
def self.standard_class_exists?(name)
|
50
50
|
class_name = name.split('_').map(&:capitalize).join
|
51
|
-
|
51
|
+
# Do it this way so the Class space isn't polluted with the classes of this script
|
52
|
+
command = "ruby -e \"puts Module.const_defined?(\\\"#{class_name}\\\").inspect\""
|
53
|
+
begin
|
54
|
+
eval(`#{command}`.chomp)
|
55
|
+
rescue
|
56
|
+
false
|
57
|
+
end
|
52
58
|
end
|
53
59
|
|
54
60
|
CHECK_METHODS = [
|
55
|
-
{method: nil, description: "Unused"},
|
56
|
-
{method: :
|
57
|
-
{method: :
|
58
|
-
{method: :
|
59
|
-
{method: :
|
60
|
-
{method: :
|
61
|
-
{method: :
|
61
|
+
{method: nil, description: "Unused"},
|
62
|
+
{method: :standard_class_exists?, description: "Class"},
|
63
|
+
{method: :ruby_gem_exists?, description: "RubyGem"},
|
64
|
+
{method: :github_repository_exists?, description: "Github repository"},
|
65
|
+
{method: :alias_exists?, description: "Alias"},
|
66
|
+
{method: :function_exists?, description: "Function"},
|
67
|
+
{method: :executable_exists?, description: "Executable"}
|
62
68
|
]
|
63
69
|
|
70
|
+
def self.check_methods
|
71
|
+
CHECK_METHODS
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.check_method(i)
|
75
|
+
CHECK_METHODS[i]
|
76
|
+
end
|
77
|
+
|
64
78
|
def self.unused_result
|
65
79
|
{check: 0, description: CHECK_METHODS[0][:description], result: true}
|
66
80
|
end
|
67
81
|
|
68
|
-
def self.
|
82
|
+
def self.check_name(check, name)
|
69
83
|
method = CHECK_METHODS[check] && CHECK_METHODS[check][:method]
|
70
84
|
if method
|
71
85
|
result = {check: check, description: CHECK_METHODS[check][:description], result: send(method, name)}
|
@@ -75,40 +89,4 @@ module GemName
|
|
75
89
|
result[:name] = name
|
76
90
|
result
|
77
91
|
end
|
78
|
-
|
79
|
-
def self.check_name(name)
|
80
|
-
name = name.downcase
|
81
|
-
result = unused_result.dup
|
82
|
-
(1...(CHECK_METHODS.size)).each do |check|
|
83
|
-
res = check_name_once(check, name)
|
84
|
-
if res[:result]
|
85
|
-
result = res
|
86
|
-
break
|
87
|
-
end
|
88
|
-
end
|
89
|
-
result[:name] = name
|
90
|
-
result
|
91
|
-
end
|
92
|
-
|
93
|
-
def self.check_name_all(name)
|
94
|
-
(1...(CHECK_METHODS.size)).map do |check|
|
95
|
-
check_name_once(check, name)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.check_names(*names)
|
100
|
-
results = []
|
101
|
-
names.each do |name|
|
102
|
-
results << check_name(name)
|
103
|
-
end
|
104
|
-
results
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.check_names_all(*names)
|
108
|
-
results = []
|
109
|
-
names.each do |name|
|
110
|
-
results += check_name_all(name)
|
111
|
-
end
|
112
|
-
results
|
113
|
-
end
|
114
92
|
end
|
data/sig/check_names.rbs
CHANGED