benry-cmdapp 1.1.0 → 1.1.2

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: 93ac71b6b3c1d20a3b3fda343372b791c284e77e3a1b475ff9ac6a7c6adec123
4
- data.tar.gz: 01a0568d79c5e94c4be53aaa9eb0766406a695c55b4c2c11222cf1c396700b87
3
+ metadata.gz: 55cda8dcd81c8ebb9de51a568d94408fc177d6f9425e25bba54b2b3cf6836762
4
+ data.tar.gz: c5d12034ccedd2fe0c18916a566588f21e58267d7e0d20d42c807d5f3134fbc1
5
5
  SHA512:
6
- metadata.gz: 71a365339d5b71b5acb46558e116991fcce7c900261b98b15dddeb50ba4fa7d50b7b6e278b22db4b3413fb171432f92369a0860df86c484b35fca8aacbb76bc3
7
- data.tar.gz: e795e95e65f1c50f3ba7123f050747f8c504f1b233839df775c8451b33983f7da5ca7829df7b6854a1e17ea6b410c336829d023a4b5659bb19b1725c66345d97
6
+ metadata.gz: d4991a36655d4ab69e709a83e8e5965c00c704d91fb9323a79db33c29d47fb08f2787add47270d42e12180cc8dbdd0a80bfe840c6624105e63fe209e09ca0f1c
7
+ data.tar.gz: d9b9a8b181fbcf9741aa4685b23a0efcf3ddf507c2363a63a8eab1d96b35f8f60e64a980834c47b37eedef71a404b28e00d4e93aa956a10b09b3f5b5e809e2ba
data/CHANGES.md CHANGED
@@ -2,6 +2,19 @@ CHANGES
2
2
  =======
3
3
 
4
4
 
5
+ Release 1.1.2 (2024-09-30)
6
+ --------------------------
7
+
8
+ * [change] Change to report error when prefix not matched any task names.
9
+ * [bugfix] Fix a minor bug related to listing candidates.
10
+
11
+
12
+ Release 1.1.1 (2023-12-29)
13
+ --------------------------
14
+
15
+ * [bugfix] Fix to print method parameter 'foo_' as 'foo' in help message.
16
+
17
+
5
18
  Release 1.1.0 (2023-12-04)
6
19
  --------------------------
7
20
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Benry-CmdApp
2
2
 
3
- ($Release: 1.1.0 $)
3
+ ($Release: 1.1.2 $)
4
4
 
5
5
 
6
6
  ## What's This?
data/benry-cmdapp.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "benry-cmdapp"
5
- spec.version = "$Release: 1.1.0 $".split()[1]
5
+ spec.version = "$Release: 1.1.2 $".split()[1]
6
6
  spec.author = "kwatch"
7
7
  spec.email = "kwatch@gmail.com"
8
8
  spec.platform = Gem::Platform::RUBY
@@ -21,7 +21,7 @@
21
21
  <ul class="nav">
22
22
  </ul>
23
23
  </nav>
24
- <p>($Release: 1.1.0 $)</p>
24
+ <p>($Release: 1.1.2 $)</p>
25
25
  <section class="section" id="whats-this">
26
26
  <h2>What's This?</h2>
27
27
  <p>Benry-CmdApp is a framework to create command-line application.
data/lib/benry/cmdapp.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 1.1.0 $
5
+ ### $Release: 1.1.2 $
6
6
  ### $Copyright: copyright(c) 2023 kwatch@gmail.com $
7
7
  ### $License: MIT License $
8
8
  ###
@@ -91,18 +91,22 @@ module Benry::CmdApp
91
91
  sb << ("]" * n) if n > 0
92
92
  #; [!mbxy5] converts `.foo(x, *x_)` into `' <x>...'`.
93
93
  #; [!mh9ni] converts `.foo(x, *x2)` into `' <x>...'`.
94
- return sb.join().sub(/<([^>]+)> \[<\1[-_2]>\.\.\.\]/, "<\\1>...")
94
+ return sb.join().sub(/<([^>]+)> \[<\1[-_2]?>\.\.\.\]/, "<\\1>...")
95
95
  end
96
96
 
97
97
  def param2arg(param)
98
98
  #; [!ahvsn] converts parameter name (Symbol) into argument name (String).
99
99
  #; [!27dpw] converts `:aa_or_bb_or_cc` into `'aa|bb|cc'`.
100
100
  #; [!to41h] converts `:aa__bb__cc` into `'aa.bb.cc'`.
101
+ #; [!cldax] converts `:aa_` into `'aa'`.
101
102
  #; [!2ma08] converts `:aa_bb_cc` into `'aa-bb-cc'`.
103
+ #; [!5d0qf] lefts `:_aa` as `'_aa'`.
102
104
  s = param.to_s
103
105
  s = s.gsub('_or_', '|') # ex: 'file_or_dir' => 'file|dir'
104
106
  s = s.gsub('__' , '.') # ex: 'file__html' => 'file.html'
107
+ s = s.gsub(/_+\z/, '') # ex: 'end_' => 'end'
105
108
  s = s.gsub('_' , '-') # ex: 'foo_bar_baz' => 'foo-bar-baz'
109
+ s = s.gsub(/\A-/ , '_') # ex: '-aa' => '_aa'
106
110
  return s
107
111
  end
108
112
 
@@ -1487,12 +1491,12 @@ module Benry::CmdApp
1487
1491
  #; [!nwwrd] if prefix is 'xxx:' and alias name is 'xxx' and action name of alias matches to 'xxx:', skip it because it will be shown in 'Aliases:' section.
1488
1492
  _category_action?(metadata, prefix)
1489
1493
  }
1490
- #s1 = str.empty? ? nil : render_section(header(:HEADER_ACTIONS), str)
1491
- s1 = render_section(header(:HEADER_ACTIONS), str)
1494
+ s1 = str.empty? ? nil : render_section(header(:HEADER_ACTIONS), str)
1492
1495
  #; [!otvbt] includes name of alias which corresponds to action starting with prefix.
1496
+ #; [!bgpsm] includes name of alias which is equal to prefix name excluding tailing ':'.
1493
1497
  #; [!h5ek7] includes hidden aliases when `all: true` passed.
1494
1498
  str = _render_metadata_list(c.format_action, all: all) {|metadata|
1495
- metadata.alias? && metadata.action.start_with?(prefix)
1499
+ metadata.alias? && (metadata.action.start_with?(prefix) || metadata.action == prefix2)
1496
1500
  }
1497
1501
  #; [!9lnn2] alias names in candidate list are sorted by action name.
1498
1502
  str = str.each_line.sort_by {|line|
@@ -1501,9 +1505,12 @@ module Benry::CmdApp
1501
1505
  }.join()
1502
1506
  #; [!80t51] alias names are displayed in separated section from actions.
1503
1507
  s2 = str.empty? ? nil : render_section(header(:HEADER_ALIASES), str)
1504
- #; [!rqx7w] returns header string if both no actions nor aliases found with names starting with prefix.
1508
+ #; [!jek9k] raises error when no actions nor aliases found starting with prefix.
1509
+ arr = [s1, s2].compact()
1510
+ ! arr.empty? or
1511
+ raise CommandError, "'#{prefix}' : Unknown prefix. (Hint: try ':' instead of '#{prefix}' to list all prefixes.)"
1505
1512
  #; [!3c3f1] returns list of actions which name starts with prefix specified.
1506
- return [s1, s2].compact().join("\n")
1513
+ return arr.join("\n")
1507
1514
  end
1508
1515
 
1509
1516
  def _category_action?(md, prefix)
data/test/help_test.rb CHANGED
@@ -728,6 +728,30 @@ END
728
728
  END
729
729
  end
730
730
 
731
+ spec "[!bgpsm] includes name of alias which is equal to prefix name excluding tailing ':'." do
732
+ HelpTestAction.class_eval do
733
+ category "p5983:", action: "aaa" do
734
+ @action.("AAA")
735
+ def aaa()
736
+ end
737
+ @action.("BBB")
738
+ def bbb()
739
+ end
740
+ end
741
+ end
742
+ Benry::CmdApp.define_alias("p59", ["p5983", "-h"]) # !!!!
743
+ x = @builder.section_candidates("p5983:")
744
+ ok {x} == <<"END"
745
+ \e[1;34mActions:\e[0m
746
+ p5983 : AAA
747
+ \e[2m (alias: p59 (with '-h'))\e[0m
748
+ p5983:bbb : BBB
749
+
750
+ \e[1;34mAliases:\e[0m
751
+ p59 : alias for 'p5983 -h'
752
+ END
753
+ end
754
+
731
755
  spec "[!h5ek7] includes hidden aliases when `all: true` passed." do
732
756
  Benry::CmdApp.define_alias("add", "git:stage", hidden: true)
733
757
  at_end { Benry::CmdApp.undef_alias("add") }
@@ -798,9 +822,11 @@ END
798
822
  ok {x} =~ /^\e\[1;34mAliases:\e\[0m$/
799
823
  end
800
824
 
801
- spec "[!rqx7w] returns header string if both no actions nor aliases found with names starting with prefix." do
802
- x = @builder.section_candidates("blabla:")
803
- ok {x} == "\e[1;34mActions:\e[0m\n\n"
825
+ spec "[!jek9k] raises error when no actions nor aliases found starting with prefix." do
826
+ pr = proc { @builder.section_candidates("blabla:") }
827
+ ok {pr}.raise?(Benry::CmdApp::CommandError,
828
+ "'blabla:' : Unknown prefix."\
829
+ " (Hint: try ':' instead of 'blabla:' to list all prefixes.)")
804
830
  end
805
831
 
806
832
  end
data/test/util_test.rb CHANGED
@@ -109,10 +109,18 @@ Oktest.scope do
109
109
  ok {Benry::CmdApp::Util.param2arg(:aa__bb__cc)} == "aa.bb.cc"
110
110
  end
111
111
 
112
+ spec "[!cldax] converts `:aa_` into `'aa'`." do
113
+ ok {Benry::CmdApp::Util.param2arg(:aa_)} == "aa"
114
+ end
115
+
112
116
  spec "[!2ma08] converts `:aa_bb_cc` into `'aa-bb-cc'`." do
113
117
  ok {Benry::CmdApp::Util.param2arg(:aa_bb_cc)} == "aa-bb-cc"
114
118
  end
115
119
 
120
+ spec "[!5d0qf] lefts `:_aa` as `'_aa'`." do
121
+ ok {Benry::CmdApp::Util.param2arg(:_aa_bb_cc_)} == "_aa-bb-cc"
122
+ end
123
+
116
124
  end
117
125
 
118
126
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benry-cmdapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kwatch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-04 00:00:00.000000000 Z
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benry-cmdopt
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.4.10
98
+ rubygems_version: 3.4.19
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Command-line application framework