yoptparse 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/lib/yoptparse.rb +6 -0
- data/lib/yoptparse/command.rb +58 -0
- data/lib/yoptparse/option.rb +91 -0
- data/lib/yoptparse/version.rb +3 -0
- data/yoptparse.gemspec +22 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9da740c1ef27e2b9fa90c8ad2e64fab52f602bb2
|
4
|
+
data.tar.gz: a0dcc13accf4cf3c963900e47eb7ac83b1fb89e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e06ff2b1d27dd969c1a52f69502e7daf669410adec76ccdfc3d52824ff1361b520aa0167c5d876235ee0ab6ff08da80dc00432344a4127508ef6ccb06d7c0c6e
|
7
|
+
data.tar.gz: e5f0469c2a8784973a458ffe073f1ca53df657560317d78df2d5138954ca613fb94f8b9c75b98259fb605f28d8c87875ebb48ca13b048faafa70c193a2aac0be
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ryo Nakamura
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Yoptparse
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/yoptparse.svg)](https://badge.fury.io/rb/yoptparse)
|
4
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/github/r7kamura/yoptparse)
|
5
|
+
[![CircleCI](https://circleci.com/gh/r7kamura/yoptparse.svg?style=svg)](https://circleci.com/gh/r7kamura/yoptparse)
|
6
|
+
|
7
|
+
Command line option parsing with [YARD](http://yardoc.org/) and optparse.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "yoptparse"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
gem install yoptparse
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Inherit `Yoptparse::Command` and define `#initialize` method with YARD style documentation.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class ExampleCommand < Yoptparse::Command
|
35
|
+
# Usage: somemoji extract [options]
|
36
|
+
# @param destination [String] Directory path to put extracted emoji images
|
37
|
+
# @param format [String] png or svg (default: png)
|
38
|
+
# @param provider [String] Emoji provider name (apple, emoji_one, noto or twemoji)
|
39
|
+
# @param quiet [Boolean] Disable log output
|
40
|
+
# @param size [Integer] Image size
|
41
|
+
def initialize(destination:, format: "png", provider:, quiet: false, size: 64)
|
42
|
+
@destination = destination
|
43
|
+
@format = format
|
44
|
+
@provider = provider
|
45
|
+
@quiet = quiet
|
46
|
+
@size = size
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
puts ExampleCommand.to_option_parser
|
51
|
+
```
|
52
|
+
|
53
|
+
```
|
54
|
+
Usage: somemoji extract [options]
|
55
|
+
--destination= Directory path to put extracted emoji images (required)
|
56
|
+
--provider= Emoji provider name (apple, emoji_one, noto or twemoji) (required)
|
57
|
+
--format= png or svg (default: png)
|
58
|
+
--quiet Disable log output
|
59
|
+
--size= Image size
|
60
|
+
```
|
61
|
+
|
62
|
+
### Documentation
|
63
|
+
|
64
|
+
See API documentation at http://www.rubydoc.info/github/r7kamura/yoptparse.
|
data/Rakefile
ADDED
data/lib/yoptparse.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Yoptparse
|
2
|
+
class Command
|
3
|
+
class << self
|
4
|
+
# @return [String]
|
5
|
+
def banner
|
6
|
+
::YARD::Registry.at("#{self}#initialize").docstring
|
7
|
+
end
|
8
|
+
|
9
|
+
# @param argv [Array<String>]
|
10
|
+
# @return [Hash{Symbol => Object}]
|
11
|
+
def parse(argv)
|
12
|
+
option_parser, result_store = generate_option_parser_and_result_store
|
13
|
+
option_parser.parse(argv)
|
14
|
+
result_store
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [OptionParser]
|
18
|
+
def to_option_parser
|
19
|
+
generate_option_parser_and_result_store.first
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
def constructor_path
|
26
|
+
instance_method(:initialize).source_location.first
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Array]
|
30
|
+
def generate_option_parser_and_result_store
|
31
|
+
load_constructor_documentation
|
32
|
+
result_store = {}
|
33
|
+
option_parser = ::OptionParser.new
|
34
|
+
option_parser.banner = banner
|
35
|
+
instance_method(:initialize).parameters.map do |argument_type, argument_name|
|
36
|
+
option = ::Yoptparse::Option.new(
|
37
|
+
argument_name: argument_name,
|
38
|
+
argument_type: argument_type,
|
39
|
+
command_class: self,
|
40
|
+
)
|
41
|
+
option_parser.on(
|
42
|
+
option.long_option,
|
43
|
+
option.type_class,
|
44
|
+
option.description,
|
45
|
+
) do |value|
|
46
|
+
result_store[argument_name] = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
[option_parser, result_store]
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [void]
|
53
|
+
def load_constructor_documentation
|
54
|
+
::YARD.parse(constructor_path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Yoptparse
|
2
|
+
class Option
|
3
|
+
# @param argument_name [Symbol]
|
4
|
+
# @param argument_type [Symbol]
|
5
|
+
# @param command_class [Class]
|
6
|
+
def initialize(argument_name:, argument_type:, command_class:)
|
7
|
+
@argument_name = argument_name
|
8
|
+
@argument_type = argument_type
|
9
|
+
@command_class = command_class
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
def description
|
14
|
+
[description_main, description_suffix].compact.join(" ")
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String]
|
18
|
+
def long_option
|
19
|
+
"--#{chain_cased_argument_name}#{long_option_suffix}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Class]
|
23
|
+
def type_class
|
24
|
+
case tag.type
|
25
|
+
when "Array"
|
26
|
+
::Array
|
27
|
+
when "Float"
|
28
|
+
::Float
|
29
|
+
when "Integer"
|
30
|
+
::Integer
|
31
|
+
when "Numeric"
|
32
|
+
::Numeric
|
33
|
+
when "OptionParser::DecimalInteger"
|
34
|
+
::OptionParser::DecimalInteger
|
35
|
+
when "OptionParser::DecimalNumeric"
|
36
|
+
::OptionParser::DecimalNumeric
|
37
|
+
when "OptionParser::OctalInteger"
|
38
|
+
::OptionParser::OctalInteger
|
39
|
+
when "String"
|
40
|
+
::String
|
41
|
+
else
|
42
|
+
::Object
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# @return [Boolean]
|
49
|
+
def boolean?
|
50
|
+
tag.type == "Boolean"
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [String]
|
54
|
+
def chain_cased_argument_name
|
55
|
+
@argument_name.to_s.gsub("_", "-")
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [String, nil]
|
59
|
+
def description_main
|
60
|
+
if tag
|
61
|
+
tag.text
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [String, nil]
|
66
|
+
def description_suffix
|
67
|
+
if required?
|
68
|
+
"(required)"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [String, nil]
|
73
|
+
def long_option_suffix
|
74
|
+
unless boolean?
|
75
|
+
"="
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [Boolean]
|
80
|
+
def required?
|
81
|
+
@argument_type == :keyreq
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [YARD::Tag, nil]
|
85
|
+
def tag
|
86
|
+
::YARD::Registry.at("#{@command_class}#initialize").tags.find do |tag|
|
87
|
+
tag.tag_name == "param" && tag.name == @argument_name.to_s
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/yoptparse.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "yoptparse/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "yoptparse"
|
7
|
+
spec.version = Yoptparse::VERSION
|
8
|
+
spec.authors = ["Ryo Nakamura"]
|
9
|
+
spec.email = ["r7kamura@gmail.com"]
|
10
|
+
spec.summary = "Command line option parsing with YARD and optparse."
|
11
|
+
spec.homepage = "https://github.com/r7kamura/yoptparse"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "yard"
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yoptparse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- r7kamura@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/yoptparse.rb
|
69
|
+
- lib/yoptparse/command.rb
|
70
|
+
- lib/yoptparse/option.rb
|
71
|
+
- lib/yoptparse/version.rb
|
72
|
+
- yoptparse.gemspec
|
73
|
+
homepage: https://github.com/r7kamura/yoptparse
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Command line option parsing with YARD and optparse.
|
97
|
+
test_files: []
|