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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff8ad36671b624aa1d94446930520fa7f61a5d88731328fa2c7f6bbf95d848a8
4
- data.tar.gz: 93c450c987bbd04f0b20a068580f00e75cf41016edcc12d32dc2559eedfef6e8
3
+ metadata.gz: ae504e219feb435833aab29f7f826cb9f06ed900332b10e49d747d5dc490c8be
4
+ data.tar.gz: cb5ab27233e327950f636f645caf75dae18cf84892b3f18c6fa838df87ba65e1
5
5
  SHA512:
6
- metadata.gz: c0cc266b825f3fda55713aa5967a03d239db5cbb445081d074b4293453e429aad3c2a59fe570b9fca513112ef35c34db820bb8b4a26d03a89be65d1c37d5f538
7
- data.tar.gz: bf3ca72be9bb7b40ca34f5497dd33b0c7b80834756c5dc13add3963c4a3c5667117dc047ee7e6234f19b42a6baf47a8fef4cfb12ae30946b912f39c4b5397c88
6
+ metadata.gz: 90bbfee00e503bad9280a5c4ed0b7f361e6d99b6586c4c9663a1bd690a31dba1314c3507fa432c95a00212ee5ce5bbb6aef6bee9c3b0531c16eed51512de086b
7
+ data.tar.gz: f88b71a7c4a3eb4f0b8f30f23e32f76a067036967692860853fe93b02798fa3135d63135d2965d3e0753b4cac746c54d4fa83892db5cc53e5594db283d739d59
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_PATH: ".gems"
data/.projectile CHANGED
@@ -1,2 +1,2 @@
1
- -.localgems/
1
+ -.gems/
2
2
  -doc/
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
- gem "optparse", github: "ruby/optparse"
4
- gem "ryo.rb", "~> 0.4", github: "0x1eef/ryo.rb", tag: "v0.4.2"
5
- gem "test-cmd.rb", "~> 0.2", github: "0x1eef/test-cmd.rb"
6
3
  gem "webrick"
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
- gem "cmd.rb", github: "0x1eef/cmd.rb"
83
- gem "ryo.rb", github: "0x1eef/ryo.rb"
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
@@ -1,3 +1,4 @@
1
+ require "bundler/setup"
1
2
  require "rake/testtask"
2
3
 
3
4
  Rake::TestTask.new do |t|
data/VERSION CHANGED
@@ -1 +1 @@
1
- v0.3.3
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 "optparse", "~> 0.3"
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 an initialize method, and an
5
- # attribute reader for an array of strings (usually ARGV). Classes
6
- # who include the {Cmd Cmd} module indirectly include this module as
7
- # well.
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,5 +1,5 @@
1
1
 
2
- module Cmd::Help
2
+ module Cmd::Mixin::Help
3
3
  def show_help(io = $stdout)
4
4
  banner = self.class.banner
5
5
  io.puts "Usage: #{banner.usage}\n\n" \
@@ -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 provides a light wrapper
8
- # around Ruby's
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
@@ -0,0 +1,5 @@
1
+ module Cmd::Mixin
2
+ require_relative "mixin/help"
3
+ require_relative "mixin/argv"
4
+ require_relative "mixin/option_parser"
5
+ end
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/mixins/argv"
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
@@ -3,3 +3,4 @@
3
3
  require "bundler/setup"
4
4
  require "test-unit"
5
5
  require "test-cmd"
6
+ require "cmd"
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.3.3
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: 2023-12-13 00:00:00.000000000 Z
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: optparse
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.3'
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.3'
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/mixins/argv.rb
148
- - lib/cmd/mixins/help.rb
149
- - lib/cmd/mixins/option_parser.rb
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.4.10
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.
@@ -1,15 +0,0 @@
1
- #main #content #filecontents p, .discussion p {
2
- max-width: 768px;
3
- }
4
-
5
- #toc {
6
- position: fixed;
7
- right: 25px;
8
- display: none;
9
- }
10
-
11
- @media screen and (min-width: 1280px) {
12
- #toc {
13
- display: block;
14
- }
15
- }
@@ -1,5 +0,0 @@
1
- def stylesheets
2
- s = super
3
- s << "css/0x1eef.css"
4
- s
5
- end
@@ -1,7 +0,0 @@
1
- ##
2
- # Sort methods in ascending order based
3
- # on the line number where a method is
4
- # defined.
5
- def sort_listing(listing)
6
- listing.sort_by { _1.files[1] }
7
- end