usage_by_example 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa6ff28e421846106e76d35e80132c514df0308c59506428c884b7fd0b5ff702
4
- data.tar.gz: dee35110be4a6d05480e067e12f913def3d52459b455232ddfc686b70a0670aa
3
+ metadata.gz: 573271b147430fa57fbc9033ba649e3f06781682e84c5fcc9a6c0f3a298384cc
4
+ data.tar.gz: eb7d882376968b14dbeff1e751aa41ac8ca4fbb9c45e990e291664b62b105554
5
5
  SHA512:
6
- metadata.gz: 2305c27d269773f2ea7ef8112bfd618385442cc59e31b1450ee741693c8254df323f129bd10ff7e8913afc05afc57ac58be154f485f5599f8b4df3422df7064b
7
- data.tar.gz: 28d398dcb1d4c5f71fa3aa14e43e646836d47bcf39c3287c7b109dbf773e80bdf75d13b04c05682553754f0378d392d04b3f7d8d1c5e79fba8cf89d317d5f4a1
6
+ metadata.gz: ea9e30bf8524063648804609da775df4f608908748cfcd46f580d77c7cbcd3a753681857e42b6328496dd5d5914a4f711a6b9b946cd68d0a06fe10357dc2622e
7
+ data.tar.gz: cce5f456d605e05c2d09938baa14c71ac0320df8a69de179920ab60a365c09d2caabbbe00f352a85d0245c34dd7e9e8ad3184c0472afe4a6b7833eb15f3c03a0
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
2
  --color
3
3
  --require spec_helper
4
+ --order random
data/Gemfile CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in usage_by_example.gemspec
6
- gemspec
5
+ gemspec # Specify your gem's dependencies in usage_by_example.gemspec
6
+
7
+ gem 'pry'
8
+ gem 'rspec'
7
9
 
8
- gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,18 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usage_by_example (0.0.0)
4
+ usage_by_example (1.0.0.beta)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- rake (13.0.6)
9
+ coderay (1.1.3)
10
+ diff-lcs (1.5.0)
11
+ method_source (1.0.0)
12
+ pry (0.14.2)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rspec (3.12.0)
16
+ rspec-core (~> 3.12.0)
17
+ rspec-expectations (~> 3.12.0)
18
+ rspec-mocks (~> 3.12.0)
19
+ rspec-core (3.12.2)
20
+ rspec-support (~> 3.12.0)
21
+ rspec-expectations (3.12.3)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.12.0)
24
+ rspec-mocks (3.12.5)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.12.0)
27
+ rspec-support (3.12.0)
10
28
 
11
29
  PLATFORMS
12
30
  x86_64-darwin-19
13
31
 
14
32
  DEPENDENCIES
15
- rake (~> 13.0)
33
+ pry
34
+ rspec
16
35
  usage_by_example!
17
36
 
18
37
  BUNDLED WITH
@@ -1,5 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UsageByExample
4
- VERSION = "0.0.0"
4
+ VERSION = '1.0.0'
5
5
  end
6
+
7
+
8
+ __END__
9
+
10
+ # Major version bump when breaking changes or new features
11
+ # Minor version bump when backward-compatible changes or enhancements
12
+ # Patch version bump when backward-compatible bug fixes, security updates etc
13
+
14
+ 1.0.0
15
+
16
+ - Extract optional and required argument names from a usage text
17
+ - Extract option names and associated argument names (if any) from a usage text
18
+ - Include help option by default
19
+ - Parse options and arguments from command-line arguments aka ARGV
20
+ - Exit gracefully or raise exceptions, depending on the exit_on_error parameter
21
+ - Implement dynamic methods for checking options and getting arguments
22
+ - Ensure correct git tag and all changes committed when building gem
23
+
24
+ 0.0.0
25
+
26
+ - Prehistory starts here...
@@ -5,6 +5,14 @@ require_relative "usage_by_example/version"
5
5
 
6
6
  class UsageByExample
7
7
 
8
+ attr_reader :argument_names_optional
9
+ attr_reader :argument_names_required
10
+ attr_reader :option_names
11
+
12
+ attr_reader :arguments
13
+ attr_reader :options
14
+
15
+
8
16
  def self.read(data)
9
17
  return new data.read
10
18
  end
@@ -46,7 +54,7 @@ class UsageByExample
46
54
  @option_names.update("-h" => :help, "--help" => :help)
47
55
  end
48
56
 
49
- def parse(argv)
57
+ def parse(argv, exit_on_error: true)
50
58
  array = argv.dup
51
59
  @arguments = {}
52
60
  @options = {}
@@ -73,6 +81,9 @@ class UsageByExample
73
81
 
74
82
  # --- 2) Parse optional arguments ---------------------------------
75
83
 
84
+ # Check any start with --, ie excess options
85
+ # Check min_length - max_length here
86
+
76
87
  stash = array.pop(@argument_names_required.length)
77
88
  @argument_names_optional.each do |argument_name|
78
89
  break if array.empty?
@@ -95,25 +106,27 @@ class UsageByExample
95
106
  if not array.empty?
96
107
  # Custom error message if most recent option did not require argument
97
108
  raise "Got unexpected argument for option #{most_recent_option}" if most_recent_option
98
- min_length = @argument_names.length
99
- max_length = @argument_names.length + @argument_names_optional.length
100
109
  raise "Expected #{min_length}#{"-#{max_length}" if max_length > min_length} arguments, got more"
101
110
  end
102
111
 
103
112
  return self
104
113
 
105
114
  rescue RuntimeError => err
106
- puts "ERROR: #{err.message}\n\n" unless err.message.empty?
107
- puts @usage
108
- exit
115
+ if exit_on_error
116
+ puts "ERROR: #{err.message}\n\n" unless err.message.empty?
117
+ puts @usage
118
+ exit
119
+ else
120
+ raise # Reraise the same exception
121
+ end
109
122
  end
110
123
 
111
124
  def method_missing(sym, *args, &block)
112
125
  case sym
113
- when /^argument_(.*)$/
126
+ when /^argument_(\w+)$/
114
127
  val = @arguments[$1]
115
128
  block && val ? block.call(val) : val
116
- when /^include_(.*)\?$/
129
+ when /^include_(\w+)\?$/
117
130
  @options[$1]
118
131
  else
119
132
  super
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usage_by_example
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Kuhn
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-26 00:00:00.000000000 Z
11
+ date: 2023-04-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: