bash_help 0.0.3 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/general_helpers.rb +33 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 555eb2d3f9ef419bcc28d4a4ccfa6dc0d4a8a8584692b0af9f67fdd8b444243b
4
- data.tar.gz: 3805ab638d2f46fd6ec6fc99fbeffd366e6a081285b36b91ae7a2b4202f2bde6
3
+ metadata.gz: e49057a292dc8396e33f338d215988ccc2aeaae7b8214af813db058e75e655c0
4
+ data.tar.gz: c9e7d9141ea7fad0b09f5ff1f7b54a1a486cc3a1bd3f70e4225a97a5c8be8683
5
5
  SHA512:
6
- metadata.gz: a2f058150c6593f7f63afdf44e380b2c7fd2e8519b880c8fadc5bd79e0be08698b2bfbce6a5ccaa7af9d8196e227aaffbe028b80cc228d025804078666524e00
7
- data.tar.gz: 9cbe77a020edd8dccc5b135eac43a85242b45f5852f11f79c328bd8b5c5afc697fb60af074801e6349e0d5b1082c8174438131b359c16e798d92769ed9af1e35
6
+ metadata.gz: 7bef055dec56ec0c6130158eb66d85b8a312003f8ab1338d84ca3034106b009bcb21b0782cf492646e118314dc7e49f7d731b5ff7923794d02f1b6abd63adca3
7
+ data.tar.gz: c5835b163e9e01c0e11fb8cf3a6c07650e77dd65c24e3e5007f4c4cfbcacb49e8a08d27864fa9db037460a63f5140245ebf1e55987e1d92c429d8c2c0c7dabde
@@ -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
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.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zack Fisher