optio 0.2.0

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 (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +14 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +43 -0
  8. data/Rakefile +51 -0
  9. data/VERSION +1 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/docs/Optio.html +110 -0
  13. data/docs/Optio/Exceptions.html +96 -0
  14. data/docs/Optio/Exceptions/SwitchAlreadyExistsError.html +103 -0
  15. data/docs/Optio/Parser.html +486 -0
  16. data/docs/README_md.html +157 -0
  17. data/docs/created.rid +6 -0
  18. data/docs/css/fonts.css +167 -0
  19. data/docs/css/rdoc.css +590 -0
  20. data/docs/fonts/Lato-Light.ttf +0 -0
  21. data/docs/fonts/Lato-LightItalic.ttf +0 -0
  22. data/docs/fonts/Lato-Regular.ttf +0 -0
  23. data/docs/fonts/Lato-RegularItalic.ttf +0 -0
  24. data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
  25. data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
  26. data/docs/images/add.png +0 -0
  27. data/docs/images/arrow_up.png +0 -0
  28. data/docs/images/brick.png +0 -0
  29. data/docs/images/brick_link.png +0 -0
  30. data/docs/images/bug.png +0 -0
  31. data/docs/images/bullet_black.png +0 -0
  32. data/docs/images/bullet_toggle_minus.png +0 -0
  33. data/docs/images/bullet_toggle_plus.png +0 -0
  34. data/docs/images/date.png +0 -0
  35. data/docs/images/delete.png +0 -0
  36. data/docs/images/find.png +0 -0
  37. data/docs/images/loadingAnimation.gif +0 -0
  38. data/docs/images/macFFBgHack.png +0 -0
  39. data/docs/images/package.png +0 -0
  40. data/docs/images/page_green.png +0 -0
  41. data/docs/images/page_white_text.png +0 -0
  42. data/docs/images/page_white_width.png +0 -0
  43. data/docs/images/plugin.png +0 -0
  44. data/docs/images/ruby.png +0 -0
  45. data/docs/images/tag_blue.png +0 -0
  46. data/docs/images/tag_green.png +0 -0
  47. data/docs/images/transparent.png +0 -0
  48. data/docs/images/wrench.png +0 -0
  49. data/docs/images/wrench_orange.png +0 -0
  50. data/docs/images/zoom.png +0 -0
  51. data/docs/index.html +159 -0
  52. data/docs/js/darkfish.js +161 -0
  53. data/docs/js/jquery.js +4 -0
  54. data/docs/js/navigation.js +142 -0
  55. data/docs/js/navigation.js.gz +0 -0
  56. data/docs/js/search.js +109 -0
  57. data/docs/js/search_index.js +1 -0
  58. data/docs/js/search_index.js.gz +0 -0
  59. data/docs/js/searcher.js +229 -0
  60. data/docs/js/searcher.js.gz +0 -0
  61. data/docs/table_of_contents.html +115 -0
  62. data/exe/optio +10 -0
  63. data/lib/optio.rb +8 -0
  64. data/lib/optio/exceptions.rb +6 -0
  65. data/lib/optio/parser.rb +96 -0
  66. data/lib/optio/version.rb +3 -0
  67. data/optio.gemspec +27 -0
  68. metadata +153 -0
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "optio"
5
+
6
+ p = Optio::Parser.new do |parser|
7
+ parser.switch :iko
8
+ end
9
+
10
+ puts p.parse.inspect
@@ -0,0 +1,8 @@
1
+ lib_dir = File.expand_path(File.join(__dir__, 'optio'))
2
+ Dir.glob(File.join(lib_dir, '**', '*')).each do |f|
3
+ require f if File.file?(f)
4
+ end
5
+
6
+ module Optio
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,6 @@
1
+ module Optio
2
+ module Exceptions
3
+ class SwitchAlreadyExistsError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,96 @@
1
+ require 'optparse'
2
+
3
+ module Optio
4
+ # A wrapper class for Ruby's {OptionParser}[https://ruby-doc.org/stdlib-2.4.1/libdoc/optparse/rdoc/OptionParser.html]
5
+ # Usage:
6
+ #
7
+ # p = Optio::Parser.new do |parser|
8
+ # parser.switch :verbose, short: 'v', desc: 'Verbose logging', type: TrueClass
9
+ # end
10
+ # p.parse! # or p.parse!(ARGV) or p.parse!(args_array)
11
+ #
12
+ # By default the arguments that are parsed are the ones in +ARGV+
13
+ #
14
+ # ==== TODO
15
+ # Implement support for sub commands;
16
+ #
17
+ # Optio::Parser.new do |parser|
18
+ # parser.subcommand :dance
19
+ # end
20
+ class Parser
21
+ def initialize(&block)
22
+ @switches = {}
23
+ @subcommands = {}
24
+ @banner = nil
25
+ @parsed_params = {}
26
+ if block_given?
27
+ yield self
28
+ end
29
+ end
30
+
31
+ # Define a switch
32
+ #
33
+ # ==== Parameters:
34
+ # switch_name::
35
+ # The name of the switch, i.e. the string that will represent the switch
36
+ # :someswitch will be parsed as +--someswitch+
37
+ # opts::
38
+ # Additional options for the switch;
39
+ # * +:desc+ - The description that will be shown for the switch.
40
+ # * +:type+ - Expected argument type, {see OptionParser for details}[https://ruby-doc.org/stdlib-2.4.1/libdoc/optparse/rdoc/OptionParser.html#class-OptionParser-label-Type+Coercion]
41
+ # * +:short:+ - The short switch, i,e +-h+ for +--help+
42
+ def switch(switch_name, opts = {})
43
+ store_parameter(switch_name, opts, @switches)
44
+ end
45
+
46
+ # TODO support sub commands
47
+ def subcommand(subcommand, opts)
48
+ store_parameter(subcommand, opts, @subcommands)
49
+ raise NotImplementedError, 'support for sub commands is not yet supported'
50
+ end
51
+
52
+ # Setup the banner for the option parser
53
+ #
54
+ # ==== Parameters:
55
+ # text::
56
+ # Banner text
57
+ def banner(text)
58
+ @banner = text
59
+ end
60
+
61
+ def parse(args = ARGV)
62
+ parsed_params = {}
63
+ rb_parser(parsed_params).parse(args)
64
+ parsed_params
65
+ end
66
+
67
+ def parse!(args = ARGV)
68
+ parsed_params = {}
69
+ rb_parser(parsed_params).parse!(args)
70
+ parsed_params
71
+ end
72
+
73
+ private
74
+
75
+ def rb_parser(parsed_params)
76
+ OptionParser.new do |rb_parser|
77
+ @switches.each do |switch, opts|
78
+ rb_parser.on("#{switch.to_s.chars.first} IKO", "--#{switch} IKO", opts[:type], opts[:desc]) do |param|
79
+ parsed_params[switch] = param
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def store_parameter(parameter, opts, mapping)
86
+ unless parameter.is_a?(Symbol) || parameter.is_a?(String)
87
+ raise ArgumentError, "parameter #{parameter} must be of types Atom or String"
88
+ end
89
+ parameter_sym = parameter.to_sym
90
+ if mapping.has_key?(parameter_sym)
91
+ raise Exceptions::SwitchAlreadyExistsError, "parameter #{parameter} already been defined"
92
+ end
93
+ mapping[parameter_sym] = opts
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module Optio
2
+ VERSION = File.read(File.join(__dir__, '..', '..', 'VERSION')).strip
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "optio/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "optio"
8
+ spec.version = Optio::VERSION
9
+ spec.authors = ["Amit Goldberg"]
10
+ spec.email = ["amit.goldberg@gmail.com"]
11
+
12
+ spec.summary = %q{}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/amitizle/optio"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'minitest', '~> 5.0'
27
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: optio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Amit Goldberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: ''
56
+ email:
57
+ - amit.goldberg@gmail.com
58
+ executables:
59
+ - optio
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - VERSION
71
+ - bin/console
72
+ - bin/setup
73
+ - docs/Optio.html
74
+ - docs/Optio/Exceptions.html
75
+ - docs/Optio/Exceptions/SwitchAlreadyExistsError.html
76
+ - docs/Optio/Parser.html
77
+ - docs/README_md.html
78
+ - docs/created.rid
79
+ - docs/css/fonts.css
80
+ - docs/css/rdoc.css
81
+ - docs/fonts/Lato-Light.ttf
82
+ - docs/fonts/Lato-LightItalic.ttf
83
+ - docs/fonts/Lato-Regular.ttf
84
+ - docs/fonts/Lato-RegularItalic.ttf
85
+ - docs/fonts/SourceCodePro-Bold.ttf
86
+ - docs/fonts/SourceCodePro-Regular.ttf
87
+ - docs/images/add.png
88
+ - docs/images/arrow_up.png
89
+ - docs/images/brick.png
90
+ - docs/images/brick_link.png
91
+ - docs/images/bug.png
92
+ - docs/images/bullet_black.png
93
+ - docs/images/bullet_toggle_minus.png
94
+ - docs/images/bullet_toggle_plus.png
95
+ - docs/images/date.png
96
+ - docs/images/delete.png
97
+ - docs/images/find.png
98
+ - docs/images/loadingAnimation.gif
99
+ - docs/images/macFFBgHack.png
100
+ - docs/images/package.png
101
+ - docs/images/page_green.png
102
+ - docs/images/page_white_text.png
103
+ - docs/images/page_white_width.png
104
+ - docs/images/plugin.png
105
+ - docs/images/ruby.png
106
+ - docs/images/tag_blue.png
107
+ - docs/images/tag_green.png
108
+ - docs/images/transparent.png
109
+ - docs/images/wrench.png
110
+ - docs/images/wrench_orange.png
111
+ - docs/images/zoom.png
112
+ - docs/index.html
113
+ - docs/js/darkfish.js
114
+ - docs/js/jquery.js
115
+ - docs/js/navigation.js
116
+ - docs/js/navigation.js.gz
117
+ - docs/js/search.js
118
+ - docs/js/search_index.js
119
+ - docs/js/search_index.js.gz
120
+ - docs/js/searcher.js
121
+ - docs/js/searcher.js.gz
122
+ - docs/table_of_contents.html
123
+ - exe/optio
124
+ - lib/optio.rb
125
+ - lib/optio/exceptions.rb
126
+ - lib/optio/parser.rb
127
+ - lib/optio/version.rb
128
+ - optio.gemspec
129
+ homepage: https://github.com/amitizle/optio
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.6.11
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: ''
153
+ test_files: []