cmd.rb 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundle/config +2 -0
- data/.projectile +1 -1
- data/Gemfile +0 -3
- data/README.md +10 -4
- data/Rakefile.rb +1 -0
- data/VERSION +1 -1
- data/cmd.rb.gemspec +1 -1
- data/lib/cmd/{mixins → mixin}/argv.rb +4 -5
- data/lib/cmd/{mixins → mixin}/help.rb +1 -1
- data/lib/cmd/{mixins → mixin}/option_parser.rb +10 -9
- data/lib/cmd/mixin.rb +5 -0
- data/lib/cmd.rb +4 -6
- data/test/cmd_test.rb +32 -0
- data/test/setup.rb +1 -0
- metadata +12 -12
- data/.yardoc-template/default/fulldoc/html/css/0x1eef.css +0 -15
- data/.yardoc-template/default/layout/html/setup.rb +0 -5
- data/.yardoc-template/default/module/setup.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae504e219feb435833aab29f7f826cb9f06ed900332b10e49d747d5dc490c8be
|
4
|
+
data.tar.gz: cb5ab27233e327950f636f645caf75dae18cf84892b3f18c6fa838df87ba65e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90bbfee00e503bad9280a5c4ed0b7f361e6d99b6586c4c9663a1bd690a31dba1314c3507fa432c95a00212ee5ce5bbb6aef6bee9c3b0531c16eed51512de086b
|
7
|
+
data.tar.gz: f88b71a7c4a3eb4f0b8f30f23e32f76a067036967692860853fe93b02798fa3135d63135d2965d3e0753b4cac746c54d4fa83892db5cc53e5594db283d739d59
|
data/.bundle/config
ADDED
data/.projectile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
-.
|
1
|
+
-.gems/
|
2
2
|
-doc/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -70,19 +70,25 @@ Options:
|
|
70
70
|
|
71
71
|
## Install
|
72
72
|
|
73
|
+
**Git**
|
74
|
+
|
73
75
|
cmd.rb is distributed as a RubyGem through its git repositories. <br>
|
74
76
|
[GitHub](https://github.com/0x1eef/cmd.rb),
|
75
77
|
and
|
76
78
|
[GitLab](https://gitlab.com/0x1eef/cmd.rb)
|
77
79
|
are available as sources.
|
78
80
|
|
79
|
-
**Gemfile**
|
80
|
-
|
81
81
|
```ruby
|
82
|
-
|
83
|
-
gem "
|
82
|
+
# Gemfile
|
83
|
+
gem "cmd.rb", github: "0x1eef/cmd.rb", tag: "v0.4.0"
|
84
84
|
```
|
85
85
|
|
86
|
+
**Rubygems.org**
|
87
|
+
|
88
|
+
cmd.rb can also be installed via rubygems.org.
|
89
|
+
|
90
|
+
gem install cmd.rb
|
91
|
+
|
86
92
|
## <a id="license"> License </a>
|
87
93
|
|
88
94
|
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
|
data/Rakefile.rb
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v0.
|
1
|
+
v0.4.0
|
data/cmd.rb.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.summary = "A library for building command-line applications, in Ruby."
|
14
14
|
gem.description = gem.summary
|
15
15
|
gem.add_runtime_dependency "ryo.rb", "~> 0.4"
|
16
|
-
gem.add_runtime_dependency "
|
16
|
+
gem.add_runtime_dependency "cli-option_parser.rb", "~> 0.5"
|
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"
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
##
|
4
|
-
# The {Cmd::ARGV} module provides
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
8
|
-
module Cmd::ARGV
|
4
|
+
# The {Cmd::Mixin::ARGV Cmd::Mixin::ARGV} module provides
|
5
|
+
# an initialize method, and an attribute reader for an
|
6
|
+
# array of strings (usually ARGV).
|
7
|
+
module Cmd::Mixin::ARGV
|
9
8
|
##
|
10
9
|
# @return [Array<String>]
|
11
10
|
# Returns an array of strings.
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "optparse"
|
4
|
-
require "ryo"
|
5
|
-
|
6
3
|
##
|
7
|
-
# The {Cmd::OptionParser Cmd::OptionParser} module
|
8
|
-
#
|
4
|
+
# The {Cmd::Mixin::OptionParser Cmd::Mixin::OptionParser} module enhances
|
5
|
+
# the functionality of Ruby's
|
9
6
|
# [OptionParser](https://docs.ruby-lang.org/en/3.2/OptionParser.html)
|
10
7
|
# class.
|
11
|
-
module Cmd::OptionParser
|
8
|
+
module Cmd::Mixin::OptionParser
|
9
|
+
require "cli-option_parser"
|
10
|
+
require "ryo"
|
11
|
+
|
12
12
|
def self.included(klass)
|
13
13
|
klass.extend(ClassMethods)
|
14
14
|
end
|
@@ -49,7 +49,7 @@ module Cmd::OptionParser
|
|
49
49
|
#
|
50
50
|
# @return [void]
|
51
51
|
def set_option(short, long, desc, as: String, default: nil)
|
52
|
-
option_parser.on(short, long, desc, as)
|
52
|
+
option_parser.on(short, long, desc, as) { _1 || true }
|
53
53
|
set_default({ short => default, long => default })
|
54
54
|
end
|
55
55
|
|
@@ -64,9 +64,9 @@ module Cmd::OptionParser
|
|
64
64
|
end
|
65
65
|
|
66
66
|
##
|
67
|
-
# (see Cmd::OptionParser#option_parser)
|
67
|
+
# (see Cmd::Mixin::OptionParser#option_parser)
|
68
68
|
def option_parser
|
69
|
-
@option_parser ||= ::OptionParser.new(nil, 26, " " * 2).tap do
|
69
|
+
@option_parser ||= CLI::OptionParser.new(nil, 26, " " * 2).tap do
|
70
70
|
_1.banner = ""
|
71
71
|
_1.on("-h", "--help", "Show help")
|
72
72
|
end
|
@@ -89,6 +89,7 @@ module Cmd::OptionParser
|
|
89
89
|
# Parses an array of strings with
|
90
90
|
# [OptionParser#parse](https://docs.ruby-lang.org/en/3.2/OptionParser.html#method-i-parse).
|
91
91
|
#
|
92
|
+
|
92
93
|
# @param [Array<String>] argv
|
93
94
|
# An array of strings
|
94
95
|
#
|
data/lib/cmd/mixin.rb
ADDED
data/lib/cmd.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Cmd
|
4
|
-
require_relative "cmd/
|
5
|
-
require_relative "cmd/mixins/help"
|
6
|
-
require_relative "cmd/mixins/option_parser"
|
4
|
+
require_relative "cmd/mixin"
|
7
5
|
|
8
|
-
include ARGV
|
9
|
-
include Help
|
6
|
+
include Mixin::ARGV
|
7
|
+
include Mixin::Help
|
10
8
|
|
11
9
|
def self.inherited(klass)
|
12
|
-
klass.class_eval { include(OptionParser) }
|
10
|
+
klass.class_eval { include(Mixin::OptionParser) }
|
13
11
|
end
|
14
12
|
end
|
data/test/cmd_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "setup"
|
2
|
+
|
3
|
+
class CmdTest < Test::Unit::TestCase
|
4
|
+
class Command < Cmd
|
5
|
+
set_banner usage: "test [OPTIONS]",
|
6
|
+
description: "..."
|
7
|
+
set_option '-f', '--foo', 'An option without an argument'
|
8
|
+
set_option '-b=ARG', '--bar=ARG', 'An option with an argument'
|
9
|
+
|
10
|
+
def run
|
11
|
+
parse_options(argv)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_foo_yes
|
16
|
+
options = Command.new(['-f']).run
|
17
|
+
assert_equal true, options.f
|
18
|
+
assert_equal true, options.foo
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_foo_no
|
22
|
+
options = Command.new([]).run
|
23
|
+
assert_equal nil, options.f
|
24
|
+
assert_equal nil, options.foo
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_bar
|
28
|
+
options = Command.new(['-b', 'foobar']).run
|
29
|
+
assert_equal 'foobar', options.b
|
30
|
+
assert_equal 'foobar', options.bar
|
31
|
+
end
|
32
|
+
end
|
data/test/setup.rb
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ryo.rb
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
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.5'
|
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.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,13 +129,11 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".bundle/config"
|
132
133
|
- ".github/workflows/tests.yml"
|
133
134
|
- ".gitignore"
|
134
135
|
- ".projectile"
|
135
136
|
- ".rubocop.yml"
|
136
|
-
- ".yardoc-template/default/fulldoc/html/css/0x1eef.css"
|
137
|
-
- ".yardoc-template/default/layout/html/setup.rb"
|
138
|
-
- ".yardoc-template/default/module/setup.rb"
|
139
137
|
- ".yardopts"
|
140
138
|
- Gemfile
|
141
139
|
- LICENSE
|
@@ -144,11 +142,13 @@ files:
|
|
144
142
|
- VERSION
|
145
143
|
- cmd.rb.gemspec
|
146
144
|
- lib/cmd.rb
|
147
|
-
- lib/cmd/
|
148
|
-
- lib/cmd/
|
149
|
-
- lib/cmd/
|
145
|
+
- lib/cmd/mixin.rb
|
146
|
+
- lib/cmd/mixin/argv.rb
|
147
|
+
- lib/cmd/mixin/help.rb
|
148
|
+
- lib/cmd/mixin/option_parser.rb
|
150
149
|
- share/examples/cmd.rb/ls
|
151
150
|
- share/examples/cmd.rb/setup.rb
|
151
|
+
- test/cmd_test.rb
|
152
152
|
- test/fakefs/.gitkeep
|
153
153
|
- test/fakefs/dev/.gitkeep
|
154
154
|
- test/fakefs/etc/.gitkeep
|
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
|
-
rubygems_version: 3.
|
177
|
+
rubygems_version: 3.5.3
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: A library for building command-line applications, in Ruby.
|