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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/general_helpers.rb +41 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e6351dbe0a2ca1473d06c15a41460079b6bc53ebd46f7a9984b8ddbb5b67f70
4
- data.tar.gz: 2c0a520522035fde608a777168ca921269cac0099ff3f202b4c05a95b79230ff
3
+ metadata.gz: 7d5ea3c23f7cfe859565d88a1b5e1cc6ea5ad45b0ba88113e0674bd68a9a7480
4
+ data.tar.gz: 01146b54892d107d977fe8f4b88197242c6d2c644e68b258afb6f77594fa3696
5
5
  SHA512:
6
- metadata.gz: 6e3a2940b69d6729f5871fce4f77f0a7044fc7052e247699bc26dca7f3040f67dcf8384d1c6d0bdec97bb8f83213125050bcbcb917c35f454caa1a1f515677cc
7
- data.tar.gz: c156f96ebf96172ebfa27fb765eaaaa4164533563c3c7ea5251dcf61082f10f4fc02ae4a9524aa7c6810b33177bb16d8e6f483068b321b8dac93f7e07203ff7f
6
+ metadata.gz: d914a3d9ba07446fe3192cea18f24c0e3859630c94af472f1267c26bcd56673a1fdd5995db5a8735f2a1374fe97e5179aa19e517f813f0a00fc6abf72cace132
7
+ data.tar.gz: 0d86f7249d67720f2893f4a671c93bfa50d24396fe26a9676ed9d92abfd7676287047b259a96037ddae8cf3da98a1d86d111e1fcc5a548f13e3c82a91e4262b1
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bash_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zack Fisher