cmdparse 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33a196cd6254f66b778a929a732504effd20e170
4
- data.tar.gz: 07691ec8406bdaaa936fb3e7572cafe1e8ec4234
3
+ metadata.gz: d8fcb2e570f788efd92d168dc0c3f4dc2008502e
4
+ data.tar.gz: 42fcef0757b5bfc74ce00dd517e448103aad1f8e
5
5
  SHA512:
6
- metadata.gz: cc1ced1a1fea8c62eaa11761d78c172bdb0769291fe27637a4ae5199bea8294a0cb78c71d7610012cc7ec36338a3625fed99d9bd5dfea13526342235f2b8170f
7
- data.tar.gz: 6f494cb30fb84875aaa584a360332e0fbd2c2cb3009afd4913ee8e22c7ea69d30396c86490ec505daadd97c430910c54aaaa50d3832cb40151dd46cc4a4b089e
6
+ metadata.gz: b75dca182871ab46fc25b11a32d4373104dc994fde0aefa3887d6b51e4eecf69260c7b740963703ab0383dbbbc196809b5293e7ea08e949c1883553677709a7c
7
+ data.tar.gz: e959185d687ed0134e3358804c6390dbb4067aa77b1f6184c33b01918935721b9451b51d297c10b444043305b6779eea04cc372d840266f1cd54f0995255459e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.0.2
@@ -270,7 +270,7 @@ $logo-color: #3A974D;
270
270
  /***************************************/
271
271
  /***************************************/
272
272
 
273
- @import url("http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400italic,700|Open+Sans+Condensed:300,700");
273
+ @import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400italic,700|Open+Sans+Condensed:300,700");
274
274
 
275
275
  /*********************************************************************************/
276
276
  /* Basic */
@@ -24,7 +24,7 @@
24
24
 
25
25
  <!-- Sidebar -->
26
26
  <div id="sidebar">
27
- <h1 id="logo"><a href="{relocatable: /}">cmdparse</a><br /><span>v 3.0.1</span></h1>
27
+ <h1 id="logo"><a href="{relocatable: /}">cmdparse</a><br /><span>v 3.0.2</span></h1>
28
28
 
29
29
  <!-- Nav -->
30
30
  <nav id="nav">
@@ -62,13 +62,10 @@
62
62
  var sc_project=10338773;
63
63
  var sc_invisible=1;
64
64
  var sc_security="7779f3af";
65
+ var scJsHost = (("https:" == document.location.protocol) ? "https://secure." : "http://www.");
66
+ document.write("<sc"+"ript type='text/javascript' src='" + scJsHost+ "statcounter.com/counter/counter.js'></"+"script>");
65
67
  </script>
66
- <script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script>
67
- <noscript><div class="statcounter">
68
- <a title="free hit counters" href="http://statcounter.com/" class="statcounter">
69
- <img class="statcounter" src="http://c.statcounter.com/10338773/0/7779f3af/1/" alt="free hit counters" />
70
- </a>
71
- </div></noscript>
68
+ <noscript><div class="statcounter"><a title="website statistics" href="http://statcounter.com/" target="_blank"><img class="statcounter" src="//c.statcounter.com/10338773/0/7779f3af/1/" alt="website statistics" /></a></div></noscript>
72
69
  <!-- End of StatCounter Code for Default Guide -->
73
70
  </body>
74
71
  </html>
@@ -5,6 +5,14 @@ sort_info: 8
5
5
  ---
6
6
  ## News
7
7
 
8
+ ### 2016-12-28 cmdparse 3.0.2 released!
9
+
10
+ Changes:
11
+
12
+ * Raise an error if too many arguments are provided for a command
13
+ * Better error message if not enough arguments are provided for a command
14
+
15
+
8
16
  ### 2015-03-14 cmdparse 3.0.1 released!
9
17
 
10
18
  Changes:
@@ -12,13 +12,42 @@ require 'optparse'
12
12
  OptionParser::Officious.delete('version')
13
13
  OptionParser::Officious.delete('help')
14
14
 
15
+
16
+ # Extension for OptionParser objects to allow access to some internals.
17
+ class OptionParser #:nodoc:
18
+
19
+ # Access the option list stack.
20
+ attr_reader :stack
21
+
22
+ # Returns +true+ if at least one local option is defined.
23
+ #
24
+ # The zeroth stack element is not respected when doing the query because it contains either the
25
+ # OptionParser::DefaultList or a CmdParse::MultiList with the global options of the
26
+ # CmdParse::CommandParser.
27
+ def options_defined?
28
+ stack[1..-1].each do |list|
29
+ list.each_option do |switch|
30
+ return true if switch.kind_of?(OptionParser::Switch) && (switch.short || switch.long)
31
+ end
32
+ end
33
+ false
34
+ end
35
+
36
+ # Returns +true+ if a banner has been set.
37
+ def banner?
38
+ !@banner.nil?
39
+ end
40
+
41
+ end
42
+
43
+
15
44
  # Namespace module for cmdparse.
16
45
  #
17
46
  # See CmdParse::CommandParser and CmdParse::Command for the two important classes.
18
47
  module CmdParse
19
48
 
20
49
  # The version of this cmdparse implemention
21
- VERSION = '3.0.1'
50
+ VERSION = '3.0.2'.freeze
22
51
 
23
52
 
24
53
  # Base class for all cmdparse errors.
@@ -76,6 +105,11 @@ module CmdParse
76
105
  reason 'Not enough arguments provided, minimum is'
77
106
  end
78
107
 
108
+ # This error is thrown when too many arguments are provided for the command.
109
+ class TooManyArgumentsError < ParseError
110
+ reason 'Too many arguments provided, maximum is'
111
+ end
112
+
79
113
  # Command Hash - will return partial key matches as well if there is a single non-ambigous
80
114
  # matching key
81
115
  class CommandHash < Hash #:nodoc:
@@ -85,7 +119,7 @@ module CmdParse
85
119
  end
86
120
 
87
121
  def [](cmd_name) #:nodoc:
88
- super or begin
122
+ super || begin
89
123
  possible = keys.select {|key| key[0, cmd_name.length] == cmd_name }
90
124
  fetch(possible[0]) if possible.size == 1
91
125
  end
@@ -125,33 +159,6 @@ module CmdParse
125
159
 
126
160
  end
127
161
 
128
- # Extension for OptionParser objects to allow access to some internals.
129
- class ::OptionParser #:nodoc:
130
-
131
- # Access the option list stack.
132
- attr_reader :stack
133
-
134
- # Returns +true+ if at least one local option is defined.
135
- #
136
- # The zeroth stack element is not respected when doing the query because it contains either the
137
- # OptionParser::DefaultList or a CmdParse::MultiList with the global options of the
138
- # CmdParse::CommandParser.
139
- def options_defined?
140
- stack[1..-1].each do |list|
141
- list.each_option do |switch|
142
- return true if ::OptionParser::Switch === switch && (switch.short || switch.long)
143
- end
144
- end
145
- false
146
- end
147
-
148
- # Returns +true+ if a banner has been set.
149
- def banner?
150
- !@banner.nil?
151
- end
152
-
153
- end
154
-
155
162
  # === Base class for commands
156
163
  #
157
164
  # This class implements all needed methods so that it can be used by the CommandParser class.
@@ -258,8 +265,8 @@ module CmdParse
258
265
  #
259
266
  # The argument +val+ needs to be +true+ or +false+.
260
267
  def takes_commands(val)
261
- if !val && commands.size > 0
262
- raise Error, "Can't change value of takes_commands to false because there are already sub-commands"
268
+ if !val && !commands.empty?
269
+ raise Error, "Can't change takes_commands to false because there are already sub-commands"
263
270
  else
264
271
  @takes_commands = val
265
272
  end
@@ -486,7 +493,7 @@ module CmdParse
486
493
  #
487
494
  # {command | other_command | another_command }
488
495
  def usage_commands
489
- (commands.size > 0 ? "{#{commands.keys.sort.join(" | ")}}" : '')
496
+ (commands.empty? ? '' : "{#{commands.keys.sort.join(" | ")}}")
490
497
  end
491
498
 
492
499
  # Returns the formatted short description.
@@ -511,7 +518,7 @@ module CmdParse
511
518
  def help_commands
512
519
  describe_commands = lambda do |command, level = 0|
513
520
  command.commands.sort.collect do |name, cmd|
514
- str = " "*level << name << (name == command.default_command ? " (*)" : '')
521
+ str = " " * level << name << (name == command.default_command ? " (*)" : '')
515
522
  str = str.ljust(command_parser.help_desc_indent) << cmd.short_desc.to_s
516
523
  str = format(str, width: command_parser.help_line_width - command_parser.help_indent,
517
524
  indent: command_parser.help_desc_indent)
@@ -527,7 +534,7 @@ module CmdParse
527
534
  # For the output format see #cond_format_help_section
528
535
  def help_arguments
529
536
  desc = @argument_desc.map {|k, v| k.to_s.ljust(command_parser.help_desc_indent) << v.to_s}
530
- cond_format_help_section('Arguments', desc, condition: @argument_desc.size > 0)
537
+ cond_format_help_section('Arguments', desc, condition: !@argument_desc.empty?)
531
538
  end
532
539
 
533
540
  # Returns the formatted option descriptions for the given OptionParser instance.
@@ -554,7 +561,7 @@ module CmdParse
554
561
 
555
562
  # For sorting commands by name.
556
563
  def <=>(other)
557
- self.name <=> other.name
564
+ name <=> other.name
558
565
  end
559
566
 
560
567
  protected
@@ -585,7 +592,7 @@ module CmdParse
585
592
  out = "#{title}:\n"
586
593
  lines = lines.flatten.join("\n").split(/\n/)
587
594
  if preformatted
588
- lines.map! {|l| ' '*command_parser.help_indent << l} if indent
595
+ lines.map! {|l| ' ' * command_parser.help_indent << l} if indent
589
596
  out << lines.join("\n")
590
597
  else
591
598
  out << format(lines.join("\n"), indent: (indent ? command_parser.help_indent : 0), indent_first_line: true)
@@ -617,11 +624,11 @@ module CmdParse
617
624
 
618
625
  content.split(/\n\n/).map do |paragraph|
619
626
  lines = []
620
- while paragraph.length > 0
627
+ unless paragraph.empty?
621
628
  unless (str = paragraph.slice!(pattern).sub(/[ \n]\z/, ''))
622
629
  str = paragraph.slice!(0, line_length)
623
630
  end
624
- lines << (lines.empty? && !indent_first_line ? '' : ' '*indent) + str.gsub(/\n/, ' ')
631
+ lines << (lines.empty? && !indent_first_line ? '' : ' ' * indent) + str.tr("\n", ' ')
625
632
  pattern = other_lines_pattern
626
633
  end
627
634
  lines.join("\n")
@@ -648,8 +655,8 @@ module CmdParse
648
655
  def initialize #:nodoc:
649
656
  super('help', takes_commands: false)
650
657
  short_desc('Provide help for individual commands')
651
- long_desc('This command prints the program help if no arguments are given. If one or ' <<
652
- 'more command names are given as arguments, these arguments are interpreted ' <<
658
+ long_desc('This command prints the program help if no arguments are given. If one or ' \
659
+ 'more command names are given as arguments, these arguments are interpreted ' \
653
660
  'as a hierachy of commands and the help for the right most command is show.')
654
661
  argument_desc(COMMAND: 'The name of a command or sub-command')
655
662
  end
@@ -666,7 +673,7 @@ module CmdParse
666
673
  end
667
674
 
668
675
  def execute(*args) #:nodoc:
669
- if args.length > 0
676
+ if !args.empty?
670
677
  cmd = command_parser.main_command
671
678
  arg = args.shift
672
679
  while !arg.nil? && cmd.commands.key?(arg)
@@ -789,8 +796,8 @@ module CmdParse
789
796
  #
790
797
  # handle_exceptions:: Set to +true+ if exceptions should be handled gracefully by showing the
791
798
  # error and a help message, or to +false+ if exception should not be handled
792
- # at all. If this options is set to :no_help, the exception is handled but no
793
- # help message is shown.
799
+ # at all. If this options is set to :no_help, the exception is handled but
800
+ # no help message is shown.
794
801
  #
795
802
  # takes_commands:: Specifies whether the main program takes any commands.
796
803
  def initialize(handle_exceptions: false, takes_commands: true)
@@ -868,7 +875,11 @@ module CmdParse
868
875
  else
869
876
  original_n = @current_command.arity
870
877
  n = (original_n < 0 ? -original_n - 1 : original_n)
871
- raise NotEnoughArgumentsError.new(n) if argv.size < n
878
+ if argv.size < n
879
+ raise NotEnoughArgumentsError.new("#{n} - #{@current_command.usage_arguments}")
880
+ elsif argv.size > n && original_n > 0
881
+ raise TooManyArgumentsError.new("#{n} - #{@current_command.usage_arguments}")
882
+ end
872
883
 
873
884
  argv.slice!(n..-1) unless original_n < 0
874
885
  @current_command.execute(*argv)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmdparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Leitner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-14 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webgen
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 2.2.2
79
+ rubygems_version: 2.6.8
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Advanced command line parser supporting commands