Class: Como::Opt
- Inherits:
-
ComoCommon
- Object
- ComoCommon
- Como::Opt
- Defined in:
- lib/como.rb
Overview
Opt includes all options spec information and parsed options and their values. Option instance is accessed with "Opt". The option status (Opt instance) can be queried with for example "given" and "value" methods.
Direct Known Subclasses
Defined Under Namespace
Classes: ErrorWithData, InvalidOption, MissingArgument
Constant Summary
- @@main =
Program i.e. highest level subcommand.
nil
- @@opts =
List of parsed option specs and option values.
[]
- @@subcmd =
Current subcommand recorded.
nil
- @@config =
Set of default configs for printout.
{ :autohelp => true, :rulehelp => false, :header => nil, :footer => nil, :subcheck => true, :check_missing => true, :check_invalid => true, :tab => 12, :help_exit => true, :copyright => true, }
Constants inherited from ComoCommon
Instance Attribute Summary (collapse)
-
- (Object) config
readonly
Opt configuration.
-
- (Object) doc
Option documentation string.
-
- (Object) given(yieldOpt = false, &prog)
(also: #given?)
Returns true if option is given, and block is not present.
-
- (Object) longOpt
Long option string.
-
- (Object) name
Option name.
-
- (Object) parent
Subcommand parent (i.e. host).
-
- (Object) rules
readonly
Opt rules.
-
- (Object) shortOpt
Short option string.
-
- (Object) subcmd
readonly
List of subcommands.
-
- (Object) subopt
readonly
List of suboptions.
-
- (Object) type
Option type.
-
- (Object) value
Option value.
Class Method Summary (collapse)
-
+ (Object) [](str)
Select option object by name.
-
+ (Object) addOpt(opt)
Add option to options list.
-
+ (Object) author
Return author.
-
+ (Object) configGet
Return default config for Como options.
-
+ (Object) configOverlay(config)
Overlay Opt default configuration options.
-
+ (Object) configSet(config)
Set default config for Como options.
-
+ (Object) current
Current subcmd processed.
-
+ (Object) default
Return arguments (options) that have no switch.
-
+ (Object) defaultOpt(doc = "No doc.")
Create default option spec, no switch.
-
+ (Object) each(&blk)
Options iterator for all options.
-
+ (Object) each_given(&blk)
Options iterator for given options.
-
+ (Object) external
Return arguments (options) that are specified as command external (i.e. after '--').
-
+ (Object) findOpt(name)
Find option by name.
-
+ (Object) full(name, opt, type, doc = "No doc.")
Create option spec.
-
+ (Object) main
Get main option.
-
+ (Object) progname
Return program name.
-
+ (Object) reset
Reset "dynamic" class members.
-
+ (Object) setMain(main)
Set main option.
-
+ (Object) setSubcmd(opt)
Set current subcmd.
-
+ (Object) subcmd(name, doc = "No doc.")
Create sub-command option spec.
-
+ (Object) year
Return program year.
Instance Method Summary (collapse)
-
- (Object) [](str)
Select option object by name operator.
-
- (Object) apply(default = nil)
Return option value if given otherwise the default.
-
- (Object) applyConfig(config)
Merge config to base config.
-
- (Object) argById(str)
Select option object by name/opt/longOpt.
-
- (Object) argByName(str)
Select option object by name.
-
- (Object) check(argsState)
Check provided args.
-
- (Object) checkAlso(opt, error, &check)
Additional option check.
-
- (Object) checkMissing
Check for any non-given required arguments recursively through hierarchy of subcommands.
-
- (Object) checkRule
Check option combination rules.
-
- (Object) cmdline
Return cmdline usage strings for options in an Array.
-
- (Object) default
Return default options.
-
- (Object) each(&blk)
Options list iterator.
-
- (Object) each_given(&blk)
Options iterator for given options.
-
- (Object) error(str)
Como error printout.
-
- (Object) findOpt(str)
Find option object by option str.
-
- (Object) givenCount
Number of given options.
-
- (Object) givenSubcmd
Return the selected subcommand.
-
- (Object) hasArg
Option requires argument?.
-
- (Object) hasMany
Option requires many arguments?.
-
- (Opt) initialize(name, opt, type, doc, value = nil)
constructor
Create Opt object:
- name
-
Option name string.
-
- (Object) isExclusive
Test if option is exclusive.
-
- (Object) isRequired
Is mandatory argument?.
-
- (Object) isSwitch
Test if option is of switch type.
-
- (Object) opt
Option's opt id.
-
- (Hash) params
Returns Hash of option value parameters.
-
- (Object) parse(args, checkInvalids = true)
Parse cmdline options from args.
-
- (Object) setRuleCheck(&rule)
Set rule checks for the option.
-
- (Object) setSubopt(opts, subs)
Set subcommand suboptions.
-
- (Object) setUsageFooter(str)
Set optional footer for "usage".
-
- (Object) setUsageHeader(str)
Set optional header for "usage".
-
- (Boolean) silent?
Test if option is silent.
-
- (Object) suball
All subcommand options, options and subcommands.
-
- (Object) suboptDoc
Return document strings for options.
-
- (Object) usage(doExit = nil, ruleHelp = nil)
Display program usage (and optionally exit).
-
- (Object) usageCommand
Usage printout for command.
-
- (Object) usageIfHelp
Display program usage (and optionally exit).
-
- (Object) usageNormal
Usage info for Opt:s.
-
- (Object) ~
Short syntax for value reference.
Methods inherited from ComoCommon
getIo, runHook, setHook, setIo
Constructor Details
- (Opt) initialize(name, opt, type, doc, value = nil)
Create Opt object:
- name
-
Option name string.
- opt
-
Switch string.
- type
-
Option type. One of:
-
:switch
-
:single
-
:multi
-
:opt_single
-
:opt_multi
-
:opt_any
-
:default
-
:exclusive
-
:silent
-
- doc
-
Option documentation.
- value
-
Default value.
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
# File 'lib/como.rb', line 1042 def initialize( name, opt, type, doc, value = nil ) @parent = nil @name = name @shortOpt = opt @longOpt = "--#{name}" @type = type @value = value @doc = doc # Whether option was set or not. @given = false @subopt = nil @subcmd = nil @rules = nil @config = @@config.dup Opt.addOpt( self ) end |
Instance Attribute Details
- (Object) config (readonly)
Opt configuration.
1020 1021 1022 |
# File 'lib/como.rb', line 1020 def config @config end |
- (Object) doc
Option documentation string.
1008 1009 1010 |
# File 'lib/como.rb', line 1008 def doc @doc end |
- (Object) given(yieldOpt = false, &prog) Also known as: given?
Returns true if option is given, and block is not present. When block is present, the block is executed (with value as parameter) if option has been given.
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
# File 'lib/como.rb', line 1438 def given( yieldOpt = false, &prog ) if block_given? if @given if yieldOpt yield( self ) else yield( @value ) end else false end else @given end end |
- (Object) longOpt
Long option string.
999 1000 1001 |
# File 'lib/como.rb', line 999 def longOpt @longOpt end |
- (Object) name
Option name.
993 994 995 |
# File 'lib/como.rb', line 993 def name @name end |
- (Object) parent
Subcommand parent (i.e. host).
989 990 991 |
# File 'lib/como.rb', line 989 def parent @parent end |
- (Object) rules (readonly)
Opt rules.
1023 1024 1025 |
# File 'lib/como.rb', line 1023 def rules @rules end |
- (Object) shortOpt
Short option string.
996 997 998 |
# File 'lib/como.rb', line 996 def shortOpt @shortOpt end |
- (Object) subcmd (readonly)
List of subcommands.
1017 1018 1019 |
# File 'lib/como.rb', line 1017 def subcmd @subcmd end |
- (Object) subopt (readonly)
List of suboptions.
1014 1015 1016 |
# File 'lib/como.rb', line 1014 def subopt @subopt end |
- (Object) type
Option type.
1002 1003 1004 |
# File 'lib/como.rb', line 1002 def type @type end |
- (Object) value
Option value.
1005 1006 1007 |
# File 'lib/como.rb', line 1005 def value @value end |
Class Method Details
+ (Object) [](str)
Select option object by name. Main is searched first and then the flattened list of all options.
889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
# File 'lib/como.rb', line 889 def Opt.[](str) # Search Main first. ret = Opt.main.argByName( str ) unless ret ret = Opt.findOpt( str ) unless ret raise RuntimeError, "Option \"#{str}\" does not exist..." end end ret end |
+ (Object) addOpt(opt)
Add option to options list.
853 854 855 |
# File 'lib/como.rb', line 853 def Opt.addOpt( opt ) @@opts.push opt end |
+ (Object) author
Return author.
918 919 920 |
# File 'lib/como.rb', line 918 def Opt. @@main. end |
+ (Object) configGet
Return default config for Como options.
971 972 973 |
# File 'lib/como.rb', line 971 def Opt.configGet @@config end |
+ (Object) configOverlay(config)
Overlay Opt default configuration options.
965 966 967 |
# File 'lib/como.rb', line 965 def Opt.configOverlay( config ) @@config.merge!( config ) end |
+ (Object) configSet(config)
Set default config for Como options. User can manipulate the defaults with "preHook".
978 979 980 |
# File 'lib/como.rb', line 978 def Opt.configSet( config ) @@config = config end |
+ (Object) current
Current subcmd processed.
865 866 867 |
# File 'lib/como.rb', line 865 def Opt.current @@subcmd end |
+ (Object) default
Return arguments (options) that have no switch.
931 932 933 |
# File 'lib/como.rb', line 931 def Opt.default Opt.main.default end |
+ (Object) defaultOpt(doc = "No doc.")
Create default option spec, no switch.
947 948 949 |
# File 'lib/como.rb', line 947 def Opt.defaultOpt( doc = "No doc." ) new( "<default>", "<default>", :default, doc, [] ) end |
+ (Object) each(&blk)
Options iterator for all options.
953 954 955 |
# File 'lib/como.rb', line 953 def Opt.each( &blk ) Opt.main.each &blk end |
+ (Object) each_given(&blk)
Options iterator for given options.
959 960 961 |
# File 'lib/como.rb', line 959 def Opt.each_given( &blk ) Opt.main.each_given( &blk ) end |
+ (Object) external
Return arguments (options) that are specified as command external (i.e. after '--').
925 926 927 |
# File 'lib/como.rb', line 925 def Opt.external Opt.main.external end |
+ (Object) findOpt(name)
Find option by name.
871 872 873 874 875 876 877 878 |
# File 'lib/como.rb', line 871 def Opt.findOpt( name ) idx = @@opts.index do |i| i.name == name end if idx @@opts[ idx ] else nil end end |
+ (Object) full(name, opt, type, doc = "No doc.")
Create option spec.
937 938 939 |
# File 'lib/como.rb', line 937 def Opt.full( name, opt, type, doc = "No doc." ) new( name, opt, type, doc ) end |
+ (Object) main
Get main option.
847 848 849 |
# File 'lib/como.rb', line 847 def Opt.main @@main end |
+ (Object) progname
Return program name.
906 907 908 |
# File 'lib/como.rb', line 906 def Opt.progname @@main.name end |
+ (Object) reset
Reset "dynamic" class members.
882 883 884 |
# File 'lib/como.rb', line 882 def Opt.reset @@opts = [] end |
+ (Object) setMain(main)
Set main option.
841 842 843 844 |
# File 'lib/como.rb', line 841 def Opt.setMain( main ) @@main = main Opt.setSubcmd( main ) end |
+ (Object) setSubcmd(opt)
Set current subcmd.
859 860 861 |
# File 'lib/como.rb', line 859 def Opt.setSubcmd( opt ) @@subcmd = opt end |
+ (Object) subcmd(name, doc = "No doc.")
Create sub-command option spec.
942 943 944 |
# File 'lib/como.rb', line 942 def Opt.subcmd( name, doc = "No doc." ) new( name, nil, :subcmd, doc, false ) end |
+ (Object) year
Return program year.
912 913 914 |
# File 'lib/como.rb', line 912 def Opt.year @@main.year end |
Instance Method Details
- (Object) [](str)
Select option object by name operator.
1368 1369 1370 1371 1372 1373 1374 |
# File 'lib/como.rb', line 1368 def []( str ) ret = argByName( str ) unless ret raise RuntimeError, "Subopt \"#{str}\" does not exist for \"#{@name}\"!" end ret end |
- (Object) apply(default = nil)
Return option value if given otherwise the default. Example usage: fileName = Opt.apply( "no_name.txt" )
1423 1424 1425 1426 1427 1428 1429 |
# File 'lib/como.rb', line 1423 def apply( default = nil ) if given value else default end end |
- (Object) applyConfig(config)
Merge config to base config.
1082 1083 1084 |
# File 'lib/como.rb', line 1082 def applyConfig( config ) @config.merge!( config ) end |
- (Object) argById(str)
Select option object by name/opt/longOpt.
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 |
# File 'lib/como.rb', line 1510 def argById( str ) if str == nil || str == :default @subopt.each do |o| if o.type == :default return o end end nil else suball.each do |o| if str == o.name || str == o.opt || str == o.longOpt return o end end nil end end |
- (Object) argByName(str)
Select option object by name.
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 |
# File 'lib/como.rb', line 1490 def argByName( str ) if str == nil || str == :default @subopt.each do |o| if o.type == :default return o end end nil else suball.each do |o| if str == o.name return o end end nil end end |
- (Object) check(argsState)
Check provided args.
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 |
# File 'lib/como.rb', line 1099 def check( argsState ) # Start at top. top = self begin # Parse and check for invalid arguments. begin top = top.parse( argsState, top.config[ :check_invalid ] ) end while( top ) # Check for any missing valid arguments. checkMissing rescue Opt::MissingArgument, Opt::InvalidOption => err error( err.to_s ) # Display subcmd specific usage info. err.data.usage exit( 1 ) end # Revert back to top after hierarchy travelsal. usageIfHelp # Check rules. cur = self while cur cur.checkRule cur = cur.givenSubcmd end self end |
- (Object) checkAlso(opt, error, &check)
Additional option check.
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
# File 'lib/como.rb', line 1348 def checkAlso( opt, error, &check ) begin if self[opt].evalCheck( &check ) != true raise Opt::InvalidOption.new( error, self ) end rescue Opt::MissingArgument, Opt::InvalidOption => err @@io.puts error( err.to_s ) err.data.usage exit( 1 ) end end |
- (Object) checkMissing
Check for any non-given required arguments recursively through hierarchy of subcommands. MissingArgument Exception is generated if argument is missing.
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 |
# File 'lib/como.rb', line 1269 def checkMissing return unless config[ :check_missing ] # Full cmd name. cmd = ( getParents.map do |i| i.name end ).join( ' ' ) # Check for any exclusive args first. @subopt.each do |o| if o.isExclusive && o.given return end end # Check for required arguments for this level before # subcmds. @subopt.each do |o| if o.isRequired unless o.given raise MissingArgument.new( "Option \"#{o.opt}\" missing for \"#{cmd}\"...", self ) end end end if hasSubcmd if @config[ :subcheck ] # Compulsory Subcommand checking enabled. subcmdMissing = true else subcmdMissing = false end else subcmdMissing = false end # Check for any subcmd args. sub = givenSubcmd if sub subcmdMissing = false # Use recursion to examine the next level. return sub.checkMissing end # If no subcmds are given, issue error. raise MissingArgument.new( "Subcommand required for \"#{cmd}\"...", self ) if subcmdMissing end |
- (Object) checkRule
Check option combination rules.
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
# File 'lib/como.rb', line 1325 def checkRule return unless @rules begin raise Opt::InvalidOption.new( "Option combination mismatch!", self ) unless RuleCheck.check( self, &@rules ) rescue Opt::MissingArgument, Opt::InvalidOption => err @@io.puts error( err.to_s ) usage( nil, true ) end end |
- (Object) cmdline
Return cmdline usage strings for options in an Array.
1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 |
# File 'lib/como.rb', line 1665 def cmdline opts = [] @subopt.each do |o| next if o.silent? prural = nil case o.type when :multi, :opt_multi; prural = "+" when :opt_any; prural = "*" else prural = "" end if !( o.isSwitch ) name = " <#{o.name}>#{prural}" else name = "" end if o.shortOpt == nil opt = o.longOpt else opt = o.shortOpt end if o.isRequired opts.push "#{opt}#{name}" else opts.push "[#{opt}#{name}]" end end if hasSubcmd opts.push "<<subcommand>>" end opts end |
- (Object) default
Return default options.
1484 1485 1486 |
# File 'lib/como.rb', line 1484 def default argByName( nil ) end |
- (Object) each(&blk)
Options list iterator.
1390 1391 1392 1393 1394 |
# File 'lib/como.rb', line 1390 def each( &blk ) suball.each do |o| yield o end end |
- (Object) each_given(&blk)
Options iterator for given options.
1398 1399 1400 1401 1402 |
# File 'lib/como.rb', line 1398 def each_given( &blk ) suball.each do |o| yield o if o.given end end |
- (Object) error(str)
Como error printout.
1749 1750 1751 |
# File 'lib/como.rb', line 1749 def error( str ) STDERR.puts "\n#{Opt.progname} error: #{str}" end |
- (Object) findOpt(str)
Find option object by option str.
1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 |
# File 'lib/como.rb', line 1735 def findOpt( str ) if str == nil suball.detect { |i| i.type == :default } elsif str[0..1] == "--" suball.detect { |i| i.longOpt == str } elsif str[0..0] != "-" suball.detect { |i| i.name == str } else suball.detect { |i| i.opt == str } end end |
- (Object) givenCount
Number of given options.
1406 1407 1408 1409 1410 1411 1412 |
# File 'lib/como.rb', line 1406 def givenCount cnt = 0 each_given do |i| cnt += 1 end cnt end |
- (Object) givenSubcmd
Return the selected subcommand.
1460 1461 1462 |
# File 'lib/como.rb', line 1460 def givenSubcmd ( @subcmd.select do |o| o.given end )[0] end |
- (Object) hasArg
Option requires argument?
1530 1531 1532 1533 1534 1535 |
# File 'lib/como.rb', line 1530 def hasArg case @type when :single, :multi, :opt_single, :opt_multi, :opt_any, :exclusive; true else false end end |
- (Object) hasMany
Option requires many arguments?
1539 1540 1541 1542 1543 1544 |
# File 'lib/como.rb', line 1539 def hasMany case @type when :multi, :opt_multi, :opt_any, :exclusive; true else false end end |
- (Object) isExclusive
Test if option is exclusive. In addition :exclusive also :silent is exclusive.
1564 1565 1566 1567 1568 1569 |
# File 'lib/como.rb', line 1564 def isExclusive case @type when :exclusive, :silent; true else false end end |
- (Object) isRequired
Is mandatory argument?
1548 1549 1550 1551 1552 1553 |
# File 'lib/como.rb', line 1548 def isRequired case @type when :single, :multi; true else false end end |
- (Object) isSwitch
Test if option is of switch type.
1573 1574 1575 1576 1577 1578 |
# File 'lib/como.rb', line 1573 def isSwitch case @type when :switch, :exclusive, :default; true else false end end |
- (Object) opt
Option's opt id. Short if exists otherwise long.
1378 1379 1380 |
# File 'lib/como.rb', line 1378 def opt @shortOpt ? @shortOpt : @longOpt end |
- (Hash) params
Returns Hash of option value parameters. Example command line content:
-p rounds=10 length=5
Option value content in this case would be (Array of param settings):
[ "rounds=10", "length=5" ]
1472 1473 1474 1475 1476 1477 1478 1479 1480 |
# File 'lib/como.rb', line 1472 def params map = {} @value.each do |i| name, value = i.split('=') value = str_to_num( value ) map[ name ] = value end map end |
- (Object) parse(args, checkInvalids = true)
Parse cmdline options from args.
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 |
# File 'lib/como.rb', line 1140 def parse( args, checkInvalids = true ) while args.get #puts "Opt.parse (#{@name}): #{args.get}" if args.isOptTerm # Rest of the args do not belong to this program. args.next Opt.main.external = args.rest break elsif args.isOpt o = findOpt( args.get ) if !o if checkInvalids raise \ InvalidOption.new( "Unknown option \"#{args.get}\"...", self ) else o = findOpt( nil ) if !o raise \ InvalidOption.new( "No default option specified to allow \"#{args.get}\"...", self ) else # Default option. o.value.push args.toValue args.next end end elsif o && o.hasArg args.next if ( !args.get || args.isOpt ) && o.type != :opt_any && o.type != :exclusive raise MissingArgument.new( "No argument given for \"#{o.opt}\"...", self ) else if o.hasMany # Get all argument for multi-option. o.value = [] if !o.given while args.get && !args.isOpt o.value.push args.toValue args.next end else # Get one argument for single-option. if o.given raise \ InvalidOption.new( "Too many arguments for option (\"#{o.name}\")...", self ) else o.value = args.toValue end args.next end end o.given = true else if !o raise InvalidOption.new( "No valid options specified...", self ) else o.given = true args.next end end else # Subcmd or default. Check for Subcmd first. # Search for Subcmd. o = findOpt( args.get ) if !o # Search for default option. o = findOpt( nil ) if !o raise \ InvalidOption.new( "No default option specified to allow \"#{args.get}\"...", self ) else # Default option. o.given = true o.value.push args.toValue args.next end else # Subcmd. o.given = true args.next return o end end end nil end |
- (Object) setRuleCheck(&rule)
Set rule checks for the option.
1090 1091 1092 |
# File 'lib/como.rb', line 1090 def setRuleCheck( &rule ) @rules = rule end |
- (Object) setSubopt(opts, subs)
Set subcommand suboptions.
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
# File 'lib/como.rb', line 1065 def setSubopt( opts, subs ) opts.each do |i| i.parent = self end subs.each do |i| i.parent = self end @subopt = opts @subcmd = subs end |
- (Object) setUsageFooter(str)
Set optional footer for "usage".
1591 1592 1593 |
# File 'lib/como.rb', line 1591 def ( str ) @config[ :footer ] = str end |
- (Object) setUsageHeader(str)
Set optional header for "usage".
1585 1586 1587 |
# File 'lib/como.rb', line 1585 def setUsageHeader( str ) @config[ :header ] = str end |
- (Boolean) silent?
Test if option is silent.
1557 1558 1559 |
# File 'lib/como.rb', line 1557 def silent? @type == :silent end |
- (Object) suball
All subcommand options, options and subcommands.
1384 1385 1386 |
# File 'lib/como.rb', line 1384 def suball @subopt + @subcmd end |
- (Object) suboptDoc
Return document strings for options.
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 |
# File 'lib/como.rb', line 1710 def suboptDoc str = "" # format = Proc.new do |s,d| ( " %-#{@config[ :tab ]}s%s\n" % [ s, d ] ) end str += "\n" str += " Options:\n" if hasSubcmd && hasVisibleOptions @subopt.each do |o| next if o.silent? str += suboptDocFormat( o.opt, o.doc ) end str += "\n" + suboptDocFormat( "Subcommands:", "" ) if hasSubcmd @subcmd.each do |o| str += suboptDocFormat( o.name, o.doc ) end str end |
- (Object) usage(doExit = nil, ruleHelp = nil)
Display program usage (and optionally exit).
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
# File 'lib/como.rb', line 1604 def usage( doExit = nil, ruleHelp = nil ) doExit = @config[ :help_exit ] if doExit == nil ruleHelp = @config[ :rulehelp ] if ruleHelp == nil @@io.puts usageNormal if ruleHelp @@io.puts "\n Option Combinations:" @@io.puts RuleDisplay.print( &@rules ) end exit( 1 ) if doExit end |
- (Object) usageCommand
Usage printout for command.
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 |
# File 'lib/como.rb', line 1631 def usageCommand str = "" str += "\ Subcommand \"#{@name}\" usage: #{fullCommand} #{cmdline.join(" ")} " str += suboptDoc str += "\n" end |
- (Object) usageIfHelp
Display program usage (and optionally exit).
1621 1622 1623 1624 1625 1626 1627 |
# File 'lib/como.rb', line 1621 def usageIfHelp if self['help'].given usage elsif hasSubcmd && givenSubcmd givenSubcmd.usageIfHelp end end |
- (Object) usageNormal
Usage info for Opt:s.
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 |
# File 'lib/como.rb', line 1643 def usageNormal str = "" if @config[ :header ] str += @config[ :header ] else str += "\n" end str += usageCommand if @config[ :footer ] str += @config[ :footer ] else str += "\n" end str end |
- (Object) ~
Short syntax for value reference. Example: "~Opt".
1416 1417 1418 |
# File 'lib/como.rb', line 1416 def ~() @value end |