usage_by_example 0.0.0 → 1.1.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: c62f93055ec627514c29cf3c8c1415f09eeb300c99e78f05f16a73bfae365c69
4
+ data.tar.gz: 5b9d24119f0ad3390a7a9b995a6e93540e0157c2c0a06e2e4453b94c42f8db4c
5
5
  SHA512:
6
- metadata.gz: 2305c27d269773f2ea7ef8112bfd618385442cc59e31b1450ee741693c8254df323f129bd10ff7e8913afc05afc57ac58be154f485f5599f8b4df3422df7064b
7
- data.tar.gz: 28d398dcb1d4c5f71fa3aa14e43e646836d47bcf39c3287c7b109dbf773e80bdf75d13b04c05682553754f0378d392d04b3f7d8d1c5e79fba8cf89d317d5f4a1
6
+ metadata.gz: ac405ec17ecf15f372b3849c18e29598d56237f625e01906a85afb528c99273836b305873901cbcd2cf2869e907c3085a7225fc43478697d06814bafe8be5dea
7
+ data.tar.gz: b334f114b4aab13a32e07a700104215075d718efc93589859ca969f69ca21a9f93edc0ee872b0b201ceedc6f3bea4e2218f21d0dbd5d175cd70e9a785c13211d
data/README.md CHANGED
@@ -1,35 +1,48 @@
1
- # UsageByExample
1
+ # Usage by Example
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/usage_by_example`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ No-code options parser that automatically detects command-line options from the usage text of your application. This intuitive parser identifies optional and required argument names as well as option names without requiring any additional code, making it easy to manage user input for your command-line applications.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Features
6
6
 
7
- ## Installation
7
+ - Automatically detects optional and required argument names from usage text
8
+ - Automatically detects option names and associated arguments (if any) from usage text
9
+ - Parses those arguments and options from the command line (ARGV)
10
+ - Raises errors for unknown options or missing required arguments
8
11
 
9
- Add this line to your application's Gemfile:
10
12
 
11
- ```ruby
12
- gem 'usage_by_example'
13
- ```
14
-
15
- And then execute:
13
+ Example
16
14
 
17
- $ bundle install
18
-
19
- Or install it yourself as:
15
+ ```ruby
16
+ require 'usage_by_example'
20
17
 
21
- $ gem install usage_by_example
18
+ Options = UsageByExample.read(DATA).parse(ARGV)
22
19
 
23
- ## Usage
20
+ puts Options.include_secure?
21
+ puts Options.include_verbose?
22
+ puts Options.include_retries?
23
+ puts Options.include_timeout?
24
+ puts Options.argument_retries
25
+ puts Options.argument_timeout
26
+ puts Options.argument_mode
27
+ puts Options.argument_host
28
+ puts Options.argument_port
24
29
 
25
- TODO: Write usage instructions here
26
30
 
27
- ## Development
31
+ __END__
32
+ Establishes a network connection to a designated host and port, enabling
33
+ users to assess network connectivity and diagnose potential problems.
28
34
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+ Usage: connect [options] [mode] host port
30
36
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+ Options:
38
+ -s, --secure Establish a secure connection (SSL/TSL)
39
+ -v, --verbose Enable verbose output for detailed information
40
+ -r, --retries NUM Specify the number of connection retries (default 3)
41
+ -t, --timeout NUM Set the connection timeout in seconds (default 10)
32
42
 
33
- ## Contributing
43
+ Arguments:
44
+ [mode] Optional connection mode (active or passive)
45
+ host The target host to connect to (e.g., example.com)
46
+ port The target port to connect to (e.g., 80)
47
+ ```
34
48
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/usage_by_example.
@@ -1,5 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UsageByExample
4
- VERSION = "0.0.0"
4
+ VERSION = '1.1.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.1
15
+
16
+ - Update readme file with features and an example
17
+ - Update the gemspec to include readme and ruby files only
18
+
19
+ 1.0.0
20
+
21
+ - Extract optional and required argument names from a usage text
22
+ - Extract option names and associated argument names (if any) from a usage text
23
+ - Include help option by default
24
+ - Parse options and arguments from command-line arguments aka ARGV
25
+ - Exit gracefully or raise exceptions, depending on the exit_on_error parameter
26
+ - Implement dynamic methods for checking options and getting arguments
27
+ - Ensure correct git tag and all changes committed when building gem
28
+
29
+ 0.0.0
30
+
31
+ - 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.1.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:
@@ -17,9 +17,6 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".rspec"
21
- - Gemfile
22
- - Gemfile.lock
23
20
  - README.md
24
21
  - lib/usage_by_example.rb
25
22
  - lib/usage_by_example/version.rb
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in usage_by_example.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
data/Gemfile.lock DELETED
@@ -1,19 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- usage_by_example (0.0.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- rake (13.0.6)
10
-
11
- PLATFORMS
12
- x86_64-darwin-19
13
-
14
- DEPENDENCIES
15
- rake (~> 13.0)
16
- usage_by_example!
17
-
18
- BUNDLED WITH
19
- 2.3.7