bash_help 0.0.4 → 0.0.6
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 +41 -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: 7d5ea3c23f7cfe859565d88a1b5e1cc6ea5ad45b0ba88113e0674bd68a9a7480
|
4
|
+
data.tar.gz: 01146b54892d107d977fe8f4b88197242c6d2c644e68b258afb6f77594fa3696
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d914a3d9ba07446fe3192cea18f24c0e3859630c94af472f1267c26bcd56673a1fdd5995db5a8735f2a1374fe97e5179aa19e517f813f0a00fc6abf72cace132
|
7
|
+
data.tar.gz: 0d86f7249d67720f2893f4a671c93bfa50d24396fe26a9676ed9d92abfd7676287047b259a96037ddae8cf3da98a1d86d111e1fcc5a548f13e3c82a91e4262b1
|
data/lib/general_helpers.rb
CHANGED
@@ -16,3 +16,44 @@ def safe_system(command)
|
|
16
16
|
exit
|
17
17
|
end
|
18
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, should_exit = true)
|
39
|
+
puts "Usage for #{method_name}:"
|
40
|
+
print_method_sig(method_name)
|
41
|
+
puts custom_usage_string
|
42
|
+
if should_exit
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# require every file in a directory.
|
48
|
+
def require_dir(directory_path)
|
49
|
+
# Get an array of all files in the directory
|
50
|
+
script_files = Dir.glob(File.join(directory_path, '*.rb'))
|
51
|
+
|
52
|
+
# Iterate over each script file
|
53
|
+
script_files.each do |script_file|
|
54
|
+
# Require or load the script file
|
55
|
+
require script_file
|
56
|
+
# Or if you want to load instead of requiring:
|
57
|
+
# load script_file
|
58
|
+
end
|
59
|
+
end
|