como 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/doc/Como/ArgsParseState.html +50 -50
- data/doc/Como/ComoCommon.html +9 -9
- data/doc/Como/MainOpt.html +126 -43
- data/doc/Como/Opt/ErrorWithData.html +10 -10
- data/doc/Como/Opt/InvalidOption.html +1 -1
- data/doc/Como/Opt/MissingArgument.html +1 -1
- data/doc/Como/Opt.html +767 -741
- data/doc/Como/RuleCheck.html +87 -87
- data/doc/Como/RuleDisplay.html +79 -79
- data/doc/Como/Spec.html +76 -90
- data/doc/Como.html +7 -6
- data/doc/_index.html +1 -1
- data/doc/file.CHANGELOG.html +9 -2
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +81 -75
- data/doc/top-level-namespace.html +1 -1
- data/lib/como.rb +160 -127
- data/test/como_compatible +1 -4
- data/test/como_config +4 -6
- data/test/como_options +2 -11
- data/test/como_queries +1 -4
- data/test/como_subcmd +2 -16
- data/test/como_subcmd_config +6 -9
- data/test/como_subcmd_rule +69 -0
- data/test/golden/compatible.txt +108 -97
- data/test/golden/config.txt +45 -149
- data/test/golden/options.txt +144 -115
- data/test/golden/queries.txt +13 -8
- data/test/golden/rule_1.txt +60 -39
- data/test/golden/rule_2.txt +60 -39
- data/test/golden/subcmd.txt +137 -131
- data/test/golden/subcmd_config.txt +162 -124
- data/test/golden/subcmd_rule.txt +366 -0
- data/test/test_como.rb +18 -9
- data/test/test_compatible +28 -28
- data/test/test_options +1 -0
- data/test/test_subcmd_rule +30 -0
- metadata +5 -2
data/lib/como.rb
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
# [author] Author of the program.
|
47
47
|
# [year] Year (or any date) for the program.
|
48
48
|
# [option table] Description of the command options.
|
49
|
-
#
|
49
|
+
#
|
50
50
|
# Each option table entry (row/sub-array) includes 4 fields and
|
51
51
|
# specifies one option:
|
52
52
|
# [ type, name, mnemonic, doc ]
|
@@ -100,17 +100,17 @@
|
|
100
100
|
# The following is displayed on the screen:
|
101
101
|
#
|
102
102
|
# como_simple error: Option "-f" missing for "como_simple"...
|
103
|
-
#
|
103
|
+
#
|
104
104
|
# Usage:
|
105
105
|
# como_simple -f <file> [-d]
|
106
|
-
#
|
106
|
+
#
|
107
107
|
# -f File argument.
|
108
108
|
# -d Enable debugging.
|
109
|
-
#
|
110
|
-
#
|
109
|
+
#
|
110
|
+
#
|
111
111
|
# Copyright (c) 2013 by Programmer
|
112
|
-
#
|
113
|
-
#
|
112
|
+
#
|
113
|
+
#
|
114
114
|
# Missing option error is displayed since "file" is a mandatory
|
115
115
|
# option. The error message is followed by "usage" display (Usage
|
116
116
|
# Help). Documentation string is taken from the option specification to
|
@@ -122,7 +122,7 @@
|
|
122
122
|
# would display the same "usage" screen except without the error
|
123
123
|
# line.
|
124
124
|
#
|
125
|
-
# ===
|
125
|
+
# === Subcommand example
|
126
126
|
#
|
127
127
|
# Subcmd example includes a program which has subcommands. Subcommands
|
128
128
|
# can have their own command line switches and options.
|
@@ -131,36 +131,36 @@
|
|
131
131
|
#
|
132
132
|
# require "como"
|
133
133
|
# include Como
|
134
|
-
#
|
134
|
+
#
|
135
135
|
# Spec.program( "Programmer", "2013" ) do
|
136
|
-
#
|
136
|
+
#
|
137
137
|
# subcmd( "como_subcmd", [
|
138
138
|
# [ :subcmd, "add", nil, "Add file." ],
|
139
139
|
# [ :subcmd, "rm", nil, "Remove file." ],
|
140
140
|
# ], )
|
141
|
-
#
|
141
|
+
#
|
142
142
|
# subcmd( "add", [
|
143
143
|
# [ :switch, "force", "-fo", "Force operation." ],
|
144
144
|
# [ :opt_single, "password", "-p", "User password." ],
|
145
145
|
# [ :opt_single, "username", "-u", "Username." ],
|
146
146
|
# [ :single, "file", "-f", "File." ],
|
147
147
|
# ] )
|
148
|
-
#
|
148
|
+
#
|
149
149
|
# checkRule do
|
150
150
|
# one(
|
151
151
|
# '-fo',
|
152
152
|
# all( 'password', 'username' )
|
153
153
|
# )
|
154
154
|
# end
|
155
|
-
#
|
155
|
+
#
|
156
156
|
# subcmd( "rm", [
|
157
157
|
# [ :single, "file", "-f", "File." ],
|
158
158
|
# ] )
|
159
|
-
#
|
159
|
+
#
|
160
160
|
# end
|
161
|
-
#
|
161
|
+
#
|
162
162
|
# subcmd = Opt.main.givenSubcmd
|
163
|
-
#
|
163
|
+
#
|
164
164
|
# case subcmd.name
|
165
165
|
# when 'add'; puts " Adding file \"#{subcmd['file'].value}\"..."
|
166
166
|
# when 'rm'; puts " Removing file \"#{subcmd['file'].value}\"..."
|
@@ -212,23 +212,23 @@
|
|
212
212
|
#
|
213
213
|
# Would result to:
|
214
214
|
# como_subcmd error: Option combination mismatch!
|
215
|
-
#
|
215
|
+
#
|
216
216
|
# Subcommand "add" usage:
|
217
217
|
# como_subcmd add [-fo] [-p <password>] [-u <username>] -f <file>
|
218
|
-
#
|
218
|
+
#
|
219
219
|
# -fo Force operation.
|
220
220
|
# -p User password.
|
221
221
|
# -u Username.
|
222
222
|
# -f File.
|
223
|
-
#
|
224
|
-
#
|
223
|
+
#
|
224
|
+
#
|
225
225
|
# Option Combinations:
|
226
226
|
# |--# One of:
|
227
227
|
# | |--<-fo>
|
228
228
|
# | |--# All of:
|
229
229
|
# | | |--<password>
|
230
230
|
# | | |--<username>
|
231
|
-
#
|
231
|
+
#
|
232
232
|
# Since the combination rule requires either "-fo" or both "password"
|
233
233
|
# and "username" in a pair.
|
234
234
|
#
|
@@ -241,9 +241,9 @@
|
|
241
241
|
#
|
242
242
|
#
|
243
243
|
# == Option specification
|
244
|
-
#
|
244
|
+
#
|
245
245
|
# === Overview
|
246
|
-
#
|
246
|
+
#
|
247
247
|
# Option specification includes the minimum set of information
|
248
248
|
# required for command line parsing. It is used to:
|
249
249
|
# * Parse the command line.
|
@@ -272,7 +272,10 @@
|
|
272
272
|
# String values can be left out, since only the document
|
273
273
|
# string is used. Default option is referred with
|
274
274
|
# ":default" or "nil".
|
275
|
-
# [:exclusive] Option that does not coexist with other
|
275
|
+
# [:exclusive] Option that does not coexist with other
|
276
|
+
# options. :exclusive can have arguments as with
|
277
|
+
# :opt_any, however :exclusive is documented like
|
278
|
+
# :switch.
|
276
279
|
# [:silent] Option that does not coexist with other options and is not
|
277
280
|
# displayed as an option in Usage Help display. In effect a
|
278
281
|
# sub-option of :exclusive.
|
@@ -297,7 +300,7 @@
|
|
297
300
|
#
|
298
301
|
#
|
299
302
|
# === Option specification method configuration
|
300
|
-
#
|
303
|
+
#
|
301
304
|
# Option behavior can be controlled with several configuration options.
|
302
305
|
#
|
303
306
|
# The configuration options are provided in a Hash. These are the
|
@@ -318,14 +321,14 @@
|
|
318
321
|
# [:subcheck] Automatically check that a subcommand is provided
|
319
322
|
# (default: true).
|
320
323
|
# [:check_missing] Check for missing arguments (default: true).
|
324
|
+
# [:check_invalid] Error for unknown options (default: true).
|
321
325
|
# [:tab] Tab stop column for option documentation (default: 12).
|
322
326
|
# [:help_exit] Exit program if help displayed (default: true).
|
323
|
-
# [:error_exit] Exit program if error in options (default: true).
|
324
327
|
#
|
325
328
|
#
|
326
329
|
#
|
327
330
|
# == Option referencing
|
328
|
-
#
|
331
|
+
#
|
329
332
|
# === Existence and values
|
330
333
|
#
|
331
334
|
# Opt class includes the parsed option values. All options can be
|
@@ -394,7 +397,7 @@
|
|
394
397
|
# RuleCheck DSL. This is needed since sometimes options have to be
|
395
398
|
# used in combination to make sense for the program. Also options
|
396
399
|
# might be mutually exclusive.
|
397
|
-
#
|
400
|
+
#
|
398
401
|
# The following rules can be used (in combination):
|
399
402
|
# [all] All options in the list.
|
400
403
|
# [one] One and only one from the list.
|
@@ -421,7 +424,7 @@ module Como
|
|
421
424
|
|
422
425
|
# IO stream options for Como classes.
|
423
426
|
class ComoCommon
|
424
|
-
|
427
|
+
|
425
428
|
# Default value for display output.
|
426
429
|
@@io = STDOUT
|
427
430
|
|
@@ -467,7 +470,7 @@ module Como
|
|
467
470
|
# (changes @@config defaults).
|
468
471
|
def Spec.command( prog, author, year, defs, config = {} )
|
469
472
|
Spec.defineCheck( prog, author, year, defs, config )
|
470
|
-
Spec.usage if Opt['help'].given
|
473
|
+
# Spec.usage if Opt['help'].given
|
471
474
|
end
|
472
475
|
|
473
476
|
# Alias to Spec.command.
|
@@ -507,7 +510,7 @@ module Como
|
|
507
510
|
unless Opt.main
|
508
511
|
|
509
512
|
main = MainOpt.new( @author, @year,
|
510
|
-
|
513
|
+
cmd, nil, :subcmd, nil )
|
511
514
|
Opt.setMain( main )
|
512
515
|
subcmd = main
|
513
516
|
|
@@ -549,7 +552,7 @@ module Como
|
|
549
552
|
table.each_index do |idx|
|
550
553
|
|
551
554
|
i = table[ idx ]
|
552
|
-
|
555
|
+
|
553
556
|
Spec.ArgCheck( i.class == Array, "Option table entry is not an Array" )
|
554
557
|
|
555
558
|
if i[0] == :default && i.length == 2
|
@@ -563,10 +566,11 @@ module Como
|
|
563
566
|
table[ idx ] = [ i[0], i[1], nil, i[2] ]
|
564
567
|
end
|
565
568
|
|
566
|
-
Spec.ArgCheck( table[ idx ].length == 4,
|
569
|
+
Spec.ArgCheck( table[ idx ].length == 4,
|
570
|
+
"Option table entry length not 4" )
|
567
571
|
end
|
568
572
|
|
569
|
-
|
573
|
+
|
570
574
|
table.each do |e|
|
571
575
|
|
572
576
|
if e[0] == :subcmd
|
@@ -579,16 +583,8 @@ module Como
|
|
579
583
|
|
580
584
|
case e[0]
|
581
585
|
|
582
|
-
when :switch
|
583
|
-
|
584
|
-
|
585
|
-
when :exclusive
|
586
|
-
option = Opt.exclusive( e[1], e[2], e[3] )
|
587
|
-
|
588
|
-
when :silent
|
589
|
-
option = Opt.exclusive( e[1], e[2], e[3], true )
|
590
|
-
|
591
|
-
when :single, :multi, :opt_single, :opt_multi, :opt_any
|
586
|
+
when :switch, :exclusive, :silent, :single, :multi,
|
587
|
+
:opt_single, :opt_multi, :opt_any
|
592
588
|
option = Opt.full( e[1], e[2], e[0], e[3] )
|
593
589
|
|
594
590
|
when :default
|
@@ -597,13 +593,13 @@ module Como
|
|
597
593
|
else
|
598
594
|
raise "Unknown option type: \"#{e[0]}\"..."
|
599
595
|
end
|
600
|
-
|
596
|
+
|
601
597
|
options[ option.name ] = option
|
602
598
|
|
603
599
|
end
|
604
|
-
|
600
|
+
|
605
601
|
end
|
606
|
-
|
602
|
+
|
607
603
|
[ options.values, subcmds.values ]
|
608
604
|
end
|
609
605
|
|
@@ -726,15 +722,15 @@ module Como
|
|
726
722
|
|
727
723
|
# Set of default configs for printout.
|
728
724
|
@@config = {
|
729
|
-
:autohelp => true,
|
730
|
-
:rulehelp => false,
|
731
|
-
:header => nil,
|
732
|
-
:footer => nil,
|
733
|
-
:subcheck => true,
|
734
|
-
:check_missing => true,
|
735
|
-
:
|
736
|
-
:
|
737
|
-
:
|
725
|
+
:autohelp => true,
|
726
|
+
:rulehelp => false,
|
727
|
+
:header => nil,
|
728
|
+
:footer => nil,
|
729
|
+
:subcheck => true,
|
730
|
+
:check_missing => true,
|
731
|
+
:check_invalid => true,
|
732
|
+
:tab => 12,
|
733
|
+
:help_exit => true,
|
738
734
|
}
|
739
735
|
|
740
736
|
|
@@ -755,12 +751,12 @@ module Como
|
|
755
751
|
@@opts.push opt
|
756
752
|
end
|
757
753
|
|
758
|
-
|
754
|
+
|
759
755
|
# Set current subcmd.
|
760
756
|
def Opt.setSubcmd( opt )
|
761
757
|
@@subcmd = opt
|
762
758
|
end
|
763
|
-
|
759
|
+
|
764
760
|
|
765
761
|
# Current subcmd processed.
|
766
762
|
def Opt.current
|
@@ -844,33 +840,24 @@ module Como
|
|
844
840
|
new( name, nil, :subcmd, doc, false )
|
845
841
|
end
|
846
842
|
|
847
|
-
# Create switch option spec.
|
848
|
-
def Opt.switch( name, opt, doc = "No doc." )
|
849
|
-
new( name, opt, :switch, doc, false )
|
850
|
-
end
|
851
|
-
|
852
|
-
# Create exclusive option spec.
|
853
|
-
def Opt.exclusive( name, opt, doc = "No doc.", silent = false )
|
854
|
-
o = new( name, opt, :exclusive, doc, false )
|
855
|
-
o.silent = silent
|
856
|
-
o
|
857
|
-
end
|
858
|
-
|
859
843
|
# Create default option spec, no switch.
|
860
844
|
def Opt.defaultOpt( doc = "No doc." )
|
861
|
-
new( "<default>", "<
|
845
|
+
new( "<default>", "<default>", :default, doc, [] )
|
862
846
|
end
|
863
847
|
|
848
|
+
|
864
849
|
# Options iterator for all options.
|
865
850
|
def Opt.each( &blk )
|
866
851
|
Opt.main.each &blk
|
867
852
|
end
|
868
853
|
|
854
|
+
|
869
855
|
# Options iterator for given options.
|
870
856
|
def Opt.each_given( &blk )
|
871
857
|
Opt.main.each_given( &blk )
|
872
858
|
end
|
873
859
|
|
860
|
+
|
874
861
|
# Overlay Opt default configuration options.
|
875
862
|
def Opt.configOverlay( config )
|
876
863
|
@@config.merge!( config )
|
@@ -889,7 +876,7 @@ module Como
|
|
889
876
|
attr_accessor :name
|
890
877
|
|
891
878
|
# Short option string.
|
892
|
-
attr_accessor :
|
879
|
+
attr_accessor :shortOpt
|
893
880
|
|
894
881
|
# Long option string.
|
895
882
|
attr_accessor :longOpt
|
@@ -906,9 +893,6 @@ module Como
|
|
906
893
|
# Is option specified?
|
907
894
|
attr_writer :given
|
908
895
|
|
909
|
-
# Is option hidden (usage).
|
910
|
-
attr_accessor :silent
|
911
|
-
|
912
896
|
# List of suboptions.
|
913
897
|
attr_reader :subopt
|
914
898
|
|
@@ -941,12 +925,11 @@ module Como
|
|
941
925
|
def initialize( name, opt, type, doc, value = nil )
|
942
926
|
@parent = nil
|
943
927
|
@name = name
|
944
|
-
@
|
928
|
+
@shortOpt = opt
|
945
929
|
@longOpt = "--#{name}"
|
946
930
|
@type = type
|
947
931
|
@value = value
|
948
932
|
@doc = doc
|
949
|
-
@silent = false
|
950
933
|
# Whether option was set or not.
|
951
934
|
@given = false
|
952
935
|
@subopt = nil
|
@@ -961,7 +944,7 @@ module Como
|
|
961
944
|
|
962
945
|
# Set subcommand suboptions.
|
963
946
|
#
|
964
|
-
# @param opts [Array<Opt>]
|
947
|
+
# @param opts [Array<Opt>]
|
965
948
|
def setSubopt( opts, subs )
|
966
949
|
opts.each do |i|
|
967
950
|
i.parent = self
|
@@ -1005,7 +988,7 @@ module Como
|
|
1005
988
|
|
1006
989
|
# Parse and check for invalid arguments.
|
1007
990
|
begin
|
1008
|
-
top = top.parse( argsState, top.config[ :
|
991
|
+
top = top.parse( argsState, top.config[ :check_invalid ] )
|
1009
992
|
end while( top )
|
1010
993
|
|
1011
994
|
# Check for any missing valid arguments.
|
@@ -1013,17 +996,14 @@ module Como
|
|
1013
996
|
|
1014
997
|
rescue Opt::MissingArgument, Opt::InvalidOption => err
|
1015
998
|
|
1016
|
-
@@io.puts
|
1017
|
-
|
1018
999
|
error( err.to_s )
|
1019
1000
|
|
1020
1001
|
# Display subcmd specific usage info.
|
1021
1002
|
err.data.usage
|
1022
1003
|
|
1023
|
-
exit( 1 )
|
1024
|
-
|
1004
|
+
exit( 1 )
|
1025
1005
|
end
|
1026
|
-
|
1006
|
+
|
1027
1007
|
# Revert back to top after hierarchy travelsal.
|
1028
1008
|
usageIfHelp
|
1029
1009
|
|
@@ -1061,13 +1041,13 @@ module Como
|
|
1061
1041
|
if checkInvalids
|
1062
1042
|
raise \
|
1063
1043
|
InvalidOption.new( "Unknown option \"#{args.get}\"...",
|
1064
|
-
|
1044
|
+
self )
|
1065
1045
|
else
|
1066
1046
|
o = findOpt( nil )
|
1067
1047
|
if !o
|
1068
1048
|
raise \
|
1069
1049
|
InvalidOption.new(
|
1070
|
-
|
1050
|
+
"No default option specified to allow \"#{args.get}\"...",
|
1071
1051
|
self )
|
1072
1052
|
else
|
1073
1053
|
# Default option.
|
@@ -1081,16 +1061,16 @@ module Como
|
|
1081
1061
|
args.next
|
1082
1062
|
|
1083
1063
|
if ( !args.get || args.isOpt ) &&
|
1084
|
-
o.type != :opt_any
|
1064
|
+
o.type != :opt_any && o.type != :exclusive
|
1085
1065
|
|
1086
1066
|
raise MissingArgument.new(
|
1087
|
-
|
1088
|
-
|
1067
|
+
"No argument given for \"#{o.opt}\"...",
|
1068
|
+
self )
|
1089
1069
|
|
1090
1070
|
else
|
1091
1071
|
|
1092
1072
|
if o.hasMany
|
1093
|
-
|
1073
|
+
|
1094
1074
|
# Get all argument for multi-option.
|
1095
1075
|
o.value = [] if !o.given
|
1096
1076
|
while args.get && !args.isOpt
|
@@ -1105,8 +1085,8 @@ module Como
|
|
1105
1085
|
if o.given
|
1106
1086
|
raise \
|
1107
1087
|
InvalidOption.new(
|
1108
|
-
|
1109
|
-
|
1088
|
+
"Too many arguments for option (\"#{o.name}\")...",
|
1089
|
+
self )
|
1110
1090
|
else
|
1111
1091
|
o.value = args.toValue
|
1112
1092
|
end
|
@@ -1120,9 +1100,8 @@ module Como
|
|
1120
1100
|
|
1121
1101
|
if !o
|
1122
1102
|
raise InvalidOption.new( "No valid options specified...",
|
1123
|
-
|
1103
|
+
self )
|
1124
1104
|
else
|
1125
|
-
o.value = !o.value if !o.given
|
1126
1105
|
o.given = true
|
1127
1106
|
args.next
|
1128
1107
|
end
|
@@ -1142,8 +1121,8 @@ module Como
|
|
1142
1121
|
if !o
|
1143
1122
|
raise \
|
1144
1123
|
InvalidOption.new(
|
1145
|
-
|
1146
|
-
|
1124
|
+
"No default option specified to allow \"#{args.get}\"...",
|
1125
|
+
self )
|
1147
1126
|
else
|
1148
1127
|
# Default option.
|
1149
1128
|
o.given = true
|
@@ -1152,11 +1131,12 @@ module Como
|
|
1152
1131
|
end
|
1153
1132
|
|
1154
1133
|
else
|
1155
|
-
|
1134
|
+
|
1135
|
+
# Subcmd.
|
1156
1136
|
o.given = true
|
1157
1137
|
args.next
|
1158
1138
|
return o
|
1159
|
-
|
1139
|
+
|
1160
1140
|
end
|
1161
1141
|
|
1162
1142
|
end
|
@@ -1171,12 +1151,14 @@ module Como
|
|
1171
1151
|
# is generated if argument is missing.
|
1172
1152
|
def checkMissing
|
1173
1153
|
|
1154
|
+
return unless config[ :check_missing ]
|
1155
|
+
|
1174
1156
|
# Full cmd name.
|
1175
1157
|
cmd = ( getParents.map do |i| i.name end ).join( ' ' )
|
1176
1158
|
|
1177
1159
|
# Check for any exclusive args first.
|
1178
1160
|
@subopt.each do |o|
|
1179
|
-
if o.
|
1161
|
+
if o.isExclusive && o.given
|
1180
1162
|
return
|
1181
1163
|
end
|
1182
1164
|
end
|
@@ -1188,8 +1170,8 @@ module Como
|
|
1188
1170
|
if o.isRequired
|
1189
1171
|
unless o.given
|
1190
1172
|
raise MissingArgument.new(
|
1191
|
-
|
1192
|
-
|
1173
|
+
"Option \"#{o.opt}\" missing for \"#{cmd}\"...",
|
1174
|
+
self )
|
1193
1175
|
end
|
1194
1176
|
end
|
1195
1177
|
end
|
@@ -1215,9 +1197,9 @@ module Como
|
|
1215
1197
|
|
1216
1198
|
# If no subcmds are given, issue error.
|
1217
1199
|
raise MissingArgument.new(
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1200
|
+
"Subcommand required for \"#{cmd}\"...",
|
1201
|
+
self ) if subcmdMissing
|
1202
|
+
|
1221
1203
|
end
|
1222
1204
|
|
1223
1205
|
|
@@ -1275,6 +1257,12 @@ module Como
|
|
1275
1257
|
end
|
1276
1258
|
|
1277
1259
|
|
1260
|
+
# Option's opt id. Short if exists otherwise long.
|
1261
|
+
def opt
|
1262
|
+
@shortOpt ? @shortOpt : @longOpt
|
1263
|
+
end
|
1264
|
+
|
1265
|
+
|
1278
1266
|
# All subcommand options, options and subcommands.
|
1279
1267
|
def suball
|
1280
1268
|
@subopt + @subcmd
|
@@ -1424,7 +1412,7 @@ module Como
|
|
1424
1412
|
# Option requires argument?
|
1425
1413
|
def hasArg
|
1426
1414
|
case @type
|
1427
|
-
when :single, :multi, :opt_single, :opt_multi, :opt_any; true
|
1415
|
+
when :single, :multi, :opt_single, :opt_multi, :opt_any, :exclusive; true
|
1428
1416
|
else false
|
1429
1417
|
end
|
1430
1418
|
end
|
@@ -1433,7 +1421,7 @@ module Como
|
|
1433
1421
|
# Option requires many arguments?
|
1434
1422
|
def hasMany
|
1435
1423
|
case @type
|
1436
|
-
when :multi, :opt_multi, :opt_any; true
|
1424
|
+
when :multi, :opt_multi, :opt_any, :exclusive; true
|
1437
1425
|
else false
|
1438
1426
|
end
|
1439
1427
|
end
|
@@ -1450,7 +1438,17 @@ module Como
|
|
1450
1438
|
|
1451
1439
|
# Test if option is silent.
|
1452
1440
|
def silent?
|
1453
|
-
@silent
|
1441
|
+
@type == :silent
|
1442
|
+
end
|
1443
|
+
|
1444
|
+
|
1445
|
+
# Test if option is exclusive. In addition :exclusive also
|
1446
|
+
# :silent is exclusive.
|
1447
|
+
def isExclusive
|
1448
|
+
case @type
|
1449
|
+
when :exclusive, :silent; true
|
1450
|
+
else false
|
1451
|
+
end
|
1454
1452
|
end
|
1455
1453
|
|
1456
1454
|
|
@@ -1487,7 +1485,7 @@ module Como
|
|
1487
1485
|
# display. Default to rulehelp config
|
1488
1486
|
# if nil.
|
1489
1487
|
def usage( doExit = nil, ruleHelp = nil )
|
1490
|
-
|
1488
|
+
|
1491
1489
|
doExit = @config[ :help_exit ] if doExit == nil
|
1492
1490
|
ruleHelp = @config[ :rulehelp ] if ruleHelp == nil
|
1493
1491
|
|
@@ -1515,7 +1513,7 @@ module Como
|
|
1515
1513
|
# Usage printout for command.
|
1516
1514
|
def usageCommand
|
1517
1515
|
str = ""
|
1518
|
-
str += "
|
1516
|
+
str += "\
|
1519
1517
|
Subcommand \"#{@name}\" usage:
|
1520
1518
|
#{fullCommand} #{cmdline.join(" ")}
|
1521
1519
|
|
@@ -1526,7 +1524,7 @@ module Como
|
|
1526
1524
|
end
|
1527
1525
|
|
1528
1526
|
# Usage info for Opt:s.
|
1529
|
-
def
|
1527
|
+
def usageNormalOld
|
1530
1528
|
str = ""
|
1531
1529
|
|
1532
1530
|
if @config[ :header ]
|
@@ -1538,7 +1536,28 @@ module Como
|
|
1538
1536
|
str += usageCommand
|
1539
1537
|
|
1540
1538
|
if @config[ :footer ]
|
1541
|
-
str += @config[ :footer ]
|
1539
|
+
str += @config[ :footer ]
|
1540
|
+
str += "\n"
|
1541
|
+
end
|
1542
|
+
|
1543
|
+
str
|
1544
|
+
end
|
1545
|
+
|
1546
|
+
# Usage info for Opt:s.
|
1547
|
+
def usageNormal
|
1548
|
+
str = ""
|
1549
|
+
|
1550
|
+
if @config[ :header ]
|
1551
|
+
str += @config[ :header ]
|
1552
|
+
else
|
1553
|
+
str += "\n"
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
str += usageCommand
|
1557
|
+
|
1558
|
+
if @config[ :footer ]
|
1559
|
+
str += @config[ :footer ]
|
1560
|
+
else
|
1542
1561
|
str += "\n"
|
1543
1562
|
end
|
1544
1563
|
|
@@ -1568,19 +1587,19 @@ module Como
|
|
1568
1587
|
name = ""
|
1569
1588
|
end
|
1570
1589
|
|
1571
|
-
if o.
|
1590
|
+
if o.shortOpt == nil
|
1572
1591
|
opt = o.longOpt
|
1573
1592
|
else
|
1574
|
-
opt = o.
|
1593
|
+
opt = o.shortOpt
|
1575
1594
|
end
|
1576
|
-
|
1595
|
+
|
1577
1596
|
if o.isRequired
|
1578
1597
|
opts.push "#{opt}#{name}"
|
1579
1598
|
else
|
1580
1599
|
opts.push "[#{opt}#{name}]"
|
1581
1600
|
end
|
1582
1601
|
end
|
1583
|
-
|
1602
|
+
|
1584
1603
|
|
1585
1604
|
if hasSubcmd
|
1586
1605
|
opts.push "<<subcommand>>"
|
@@ -1597,11 +1616,11 @@ module Como
|
|
1597
1616
|
str = ""
|
1598
1617
|
# format = Proc.new do |s,d| ( " %-#{@config[ :tab ]}s%s\n" % [ s, d ] ) end
|
1599
1618
|
|
1600
|
-
str +=
|
1619
|
+
str += " Options:\n" if hasSubcmd && hasVisibleOptions
|
1601
1620
|
|
1602
1621
|
@subopt.each do |o|
|
1603
1622
|
next if o.silent?
|
1604
|
-
str += suboptDocFormat( o.opt
|
1623
|
+
str += suboptDocFormat( o.opt, o.doc )
|
1605
1624
|
end
|
1606
1625
|
|
1607
1626
|
str += "\n" + suboptDocFormat( "Subcommands:", "" ) if hasSubcmd
|
@@ -1626,14 +1645,14 @@ module Como
|
|
1626
1645
|
suball.detect { |i| i.opt == str }
|
1627
1646
|
end
|
1628
1647
|
end
|
1629
|
-
|
1648
|
+
|
1630
1649
|
|
1631
1650
|
# Como error printout.
|
1632
1651
|
def error( str )
|
1633
|
-
|
1652
|
+
STDERR.puts "\n#{Opt.progname} error: #{str}"
|
1634
1653
|
end
|
1635
1654
|
|
1636
|
-
|
1655
|
+
|
1637
1656
|
|
1638
1657
|
|
1639
1658
|
# ------------------------------------------------------------
|
@@ -1705,7 +1724,7 @@ module Como
|
|
1705
1724
|
|
1706
1725
|
parts = doc.split( "\n" )
|
1707
1726
|
lines = [ ( " %-#{@config[ :tab ]}s%s\n" % [ switch, parts[0] ] ) ]
|
1708
|
-
|
1727
|
+
|
1709
1728
|
if parts[1]
|
1710
1729
|
parts[1..-1].each do |p|
|
1711
1730
|
|
@@ -1714,7 +1733,7 @@ module Como
|
|
1714
1733
|
else
|
1715
1734
|
lines.push p
|
1716
1735
|
end
|
1717
|
-
|
1736
|
+
|
1718
1737
|
end
|
1719
1738
|
end
|
1720
1739
|
|
@@ -1731,10 +1750,10 @@ module Como
|
|
1731
1750
|
|
1732
1751
|
# Program external arguments:
|
1733
1752
|
attr_accessor :external
|
1734
|
-
|
1753
|
+
|
1735
1754
|
# Program author and year (date).
|
1736
1755
|
attr_reader :author, :year
|
1737
|
-
|
1756
|
+
|
1738
1757
|
|
1739
1758
|
def initialize( author, year,
|
1740
1759
|
name, opt, type, doc, value = nil )
|
@@ -1744,7 +1763,7 @@ module Como
|
|
1744
1763
|
super( name, opt, type, doc, value = nil )
|
1745
1764
|
|
1746
1765
|
end
|
1747
|
-
|
1766
|
+
|
1748
1767
|
|
1749
1768
|
# Full command name.
|
1750
1769
|
def fullCommand
|
@@ -1753,7 +1772,7 @@ module Como
|
|
1753
1772
|
|
1754
1773
|
|
1755
1774
|
# Usage printout for command.
|
1756
|
-
def
|
1775
|
+
def usageCommandOld
|
1757
1776
|
str = "
|
1758
1777
|
Usage:
|
1759
1778
|
#{fullCommand} #{cmdline.join(" ")}
|
@@ -1765,6 +1784,20 @@ module Como
|
|
1765
1784
|
|
1766
1785
|
Copyright (c) #{Opt.year} by #{Opt.author}
|
1767
1786
|
|
1787
|
+
"
|
1788
|
+
end
|
1789
|
+
|
1790
|
+
# Usage printout for command.
|
1791
|
+
def usageCommand
|
1792
|
+
str = "\
|
1793
|
+
#{fullCommand} #{cmdline.join(" ")}
|
1794
|
+
|
1795
|
+
"
|
1796
|
+
str += suboptDoc
|
1797
|
+
|
1798
|
+
str += "
|
1799
|
+
|
1800
|
+
Copyright (c) #{Opt.year} by #{Opt.author}
|
1768
1801
|
"
|
1769
1802
|
end
|
1770
1803
|
|
@@ -1888,7 +1921,7 @@ module Como
|
|
1888
1921
|
# Incremental options in order i.e. have to have previous
|
1889
1922
|
# to have later.
|
1890
1923
|
def incr( *args )
|
1891
|
-
|
1924
|
+
|
1892
1925
|
# Opts given consecutive.
|
1893
1926
|
consecutiveCnt = 0
|
1894
1927
|
|