cmd.rb 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/cmd.rb.gemspec +2 -2
- data/lib/cmd/mixin/option_parser/finder.rb +23 -0
- data/lib/cmd/mixin/option_parser.rb +4 -20
- data/lib/cmd.rb +9 -1
- data/share/examples/cmd.rb/ls +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caf92ed899d22aeb7085997214b3414b42ce770e31f236377e7d59c28be23338
|
4
|
+
data.tar.gz: 2e45cc4c2f1540ed92d109eaada6aa68a62b56ecc527c75c53d93eb4b410531d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b36a32a0df0801369c86b2b774c57d968ec0ceb438068dd1346a8a56794db2389838912b1871e621f25e4e0d1611762f26339ecc0fbf05efcabca7727995f405
|
7
|
+
data.tar.gz: 716e07fe4d6409d181ada49e50bda8afc97837f3c798d0a0eec5ac0d795a6957bf2d6ad305f7ebd700348257049e8a15e761ac623429596e750affbbdf15cc2d
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v0.
|
1
|
+
v0.5.1
|
data/cmd.rb.gemspec
CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.require_paths = ["lib"]
|
13
13
|
gem.summary = "A library for building command-line applications, in Ruby."
|
14
14
|
gem.description = gem.summary
|
15
|
-
gem.add_runtime_dependency "ryo.rb", "~> 0.
|
16
|
-
gem.add_runtime_dependency "cli-option_parser.rb", "~> 0.
|
15
|
+
gem.add_runtime_dependency "ryo.rb", "~> 0.5"
|
16
|
+
gem.add_runtime_dependency "cli-option_parser.rb", "~> 0.6"
|
17
17
|
gem.add_development_dependency "test-unit", "~> 3.5.7"
|
18
18
|
gem.add_development_dependency "yard", "~> 0.9"
|
19
19
|
gem.add_development_dependency "redcarpet", "~> 3.5"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Cmd::Mixin::OptionParser
|
2
|
+
module Finder
|
3
|
+
extend self
|
4
|
+
##
|
5
|
+
# @param [CLI::OptionParser] option_parser
|
6
|
+
# An instance of CLI::OptionParser.
|
7
|
+
#
|
8
|
+
# @param [String] short
|
9
|
+
# Short option.
|
10
|
+
#
|
11
|
+
# @param [String] long
|
12
|
+
# Long option.
|
13
|
+
#
|
14
|
+
# @return [CLI::OptionParser::Switch, nil]
|
15
|
+
# Returns a Switch, or nil.
|
16
|
+
def find(option_parser, short:, long:)
|
17
|
+
option_parser.top.list.find do |s|
|
18
|
+
s.short[0] == short[/[^\s]*/] &&
|
19
|
+
s.long[0] == long[/[^\s*]*/]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# [OptionParser](https://docs.ruby-lang.org/en/3.2/OptionParser.html)
|
7
7
|
# class.
|
8
8
|
module Cmd::Mixin::OptionParser
|
9
|
+
require_relative "option_parser/finder"
|
9
10
|
require "cli-option_parser"
|
10
11
|
require "ryo"
|
11
12
|
|
@@ -50,8 +51,9 @@ module Cmd::Mixin::OptionParser
|
|
50
51
|
# @return [void]
|
51
52
|
def set_option(short, long, desc, as: String, default: nil)
|
52
53
|
option_parser.on(short, long, desc, as) do |v|
|
53
|
-
switch =
|
54
|
-
|
54
|
+
switch = Finder.find(option_parser, short:, long:)
|
55
|
+
is_optional = option_parser.optional_switches.any? { _1 === switch }
|
56
|
+
v || is_optional ? v : true
|
55
57
|
end
|
56
58
|
switch = option_parser.top.list[-1]
|
57
59
|
set_default({
|
@@ -94,24 +96,6 @@ module Cmd::Mixin::OptionParser
|
|
94
96
|
def defaults
|
95
97
|
@defaults ||= Ryo({})
|
96
98
|
end
|
97
|
-
|
98
|
-
##
|
99
|
-
# @private
|
100
|
-
def __switch_search(short, long)
|
101
|
-
option_parser.top.list.find do |s|
|
102
|
-
s.short[0] == short[/[^\s]*/] &&
|
103
|
-
s.long[0] == long[/[^\s*]*/]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
##
|
108
|
-
# @private
|
109
|
-
def __optional_switches
|
110
|
-
[
|
111
|
-
CLI::OptionParser::Switch::PlacedArgument,
|
112
|
-
CLI::OptionParser::Switch::OptionalArgument
|
113
|
-
]
|
114
|
-
end
|
115
99
|
end
|
116
100
|
|
117
101
|
##
|
data/lib/cmd.rb
CHANGED
@@ -7,6 +7,14 @@ class Cmd
|
|
7
7
|
include Mixin::Help
|
8
8
|
|
9
9
|
def self.inherited(klass)
|
10
|
-
klass.class_eval
|
10
|
+
klass.class_eval do
|
11
|
+
include Mixin::OptionParser
|
12
|
+
prepend Module.new {
|
13
|
+
def run(...)
|
14
|
+
options = parse_options(argv)
|
15
|
+
options.help ? show_help : super(...)
|
16
|
+
end
|
17
|
+
}
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
data/share/examples/cmd.rb/ls
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmd.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ryo.rb
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cli-option_parser.rb
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/cmd/mixin/argv.rb
|
147
147
|
- lib/cmd/mixin/help.rb
|
148
148
|
- lib/cmd/mixin/option_parser.rb
|
149
|
+
- lib/cmd/mixin/option_parser/finder.rb
|
149
150
|
- share/examples/cmd.rb/ls
|
150
151
|
- share/examples/cmd.rb/setup.rb
|
151
152
|
- test/cmd_test.rb
|