bash_help 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/general_helpers.rb +33 -0
- 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: e49057a292dc8396e33f338d215988ccc2aeaae7b8214af813db058e75e655c0
|
4
|
+
data.tar.gz: c9e7d9141ea7fad0b09f5ff1f7b54a1a486cc3a1bd3f70e4225a97a5c8be8683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bef055dec56ec0c6130158eb66d85b8a312003f8ab1338d84ca3034106b009bcb21b0782cf492646e118314dc7e49f7d731b5ff7923794d02f1b6abd63adca3
|
7
|
+
data.tar.gz: c5835b163e9e01c0e11fb8cf3a6c07650e77dd65c24e3e5007f4c4cfbcacb49e8a08d27864fa9db037460a63f5140245ebf1e55987e1d92c429d8c2c0c7dabde
|
data/lib/general_helpers.rb
CHANGED
@@ -8,3 +8,36 @@ def normalize(path)
|
|
8
8
|
dirpath = File.dirname(filepath)
|
9
9
|
Dir.chdir(dirpath)
|
10
10
|
end
|
11
|
+
|
12
|
+
# system(command), but aborts if the command fails.
|
13
|
+
def safe_system(command)
|
14
|
+
unless system(command)
|
15
|
+
puts "Command '#{command}' failed. Aborting."
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# for generating usage strings.
|
21
|
+
def print_method_sig(method_name)
|
22
|
+
method_obj = method(method_name)
|
23
|
+
param_list = method_obj.parameters.map do |type, name|
|
24
|
+
case type
|
25
|
+
when :req then name.to_s
|
26
|
+
when :opt then "#{name} = <default_value>"
|
27
|
+
when :rest then "*#{name}"
|
28
|
+
when :keyreq then "#{name}:"
|
29
|
+
when :key then "#{name}: <default_value>"
|
30
|
+
when :keyrest then "**#{name}"
|
31
|
+
when :block then "&#{name}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
puts "#{method_name}(#{param_list.join(', ')})"
|
35
|
+
end
|
36
|
+
|
37
|
+
# function usage string, with a custom string param that formats it for you.
|
38
|
+
def usage(method_name, custom_usage_string)
|
39
|
+
puts "Usage for #{method_name}:"
|
40
|
+
print_method_sig(method_name)
|
41
|
+
puts custom_usage_string
|
42
|
+
exit
|
43
|
+
end
|