barmcakes 0.0.1 → 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 (2) hide show
  1. data/lib/arrghs.rb +22 -2
  2. metadata +2 -2
data/lib/arrghs.rb CHANGED
@@ -2,12 +2,22 @@
2
2
  class Arrghs
3
3
  attr_reader :args
4
4
 
5
- def self.parse(arg_arr)
5
+ def self.parse_and_check(arg_arr=ARGV, needed)
6
+ args = Arrghs.parse(arg_arr)
7
+ missing = []
8
+ needed.each do |opt,desc|
9
+ missing << [opt,desc] unless args.include?(opt.gsub(/^-{1,2}/, "").to_sym)
10
+ end
11
+ return args if missing.empty?
12
+ Arrghs.die_noisily_about needed
13
+ end
14
+
15
+ def self.parse(arg_arr=ARGV)
6
16
  args = {}
7
17
  arg_arr.each_with_index do |opt, i|
8
- #$stderr.puts opt, i
9
18
  if opt =~ /^-{1,1}[^-]/
10
19
  opt = opt[1..-1]
20
+ next if opt.length > 1
11
21
  val = true
12
22
  val = arg_arr[i + 1] if arg_arr[i + 1] !~ /^-/
13
23
  opt.split(//).each {|f| args[f.to_sym] = val}
@@ -18,4 +28,14 @@ class Arrghs
18
28
  end
19
29
  args
20
30
  end
31
+
32
+ def self.die_noisily_about needed
33
+ $stderr.puts "Missing options\n"
34
+ $stderr.puts "Usage: #{$0} "
35
+ $stderr.puts "with options:"
36
+ needed.each {|opt,desc| $stderr.puts "#{opt} <#{desc}> "}
37
+ $stderr.puts "\n__________\n"
38
+ exit
39
+ end
40
+
21
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barmcakes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,7 +21,7 @@ files:
21
21
  - lib/barmcakes.rb
22
22
  - lib/arrghs.rb
23
23
  - lib/file.rb
24
- homepage: http://github.com/danmaclean
24
+ homepage: http://github.com/danmaclean/barmcakes
25
25
  licenses: []
26
26
  post_install_message:
27
27
  rdoc_options: []