# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com># # Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to deal# in the Software without restriction, including without limitation the rights# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell# copies of the Software, and to permit persons to whom the Software is# furnished to do so, subject to the following conditions:# # The above copyright notice and this permission notice shall be included in# all copies or substantial portions of the Software.# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN# THE SOFTWARE.require_relative'table'require_relative'options'require_relative'nested'require_relative'one'require_relative'many'require_relative'split'require_relative'output'require_relative'command/system'require_relative'command/track_time'moduleSamovarclassIncompleteParse<StandardErrorendclassCommanddefself.parse(input)command=self.new(input)raiseIncompleteParse.new("Could not parse #{input}")unlessinput.empty?returncommandenddefinitialize(input=nil)self.class.table.parse(input)do|key,value|self.send("#{key}=",value)endifinputenddef[]key@attributes[key]endclass<<selfattr_accessor:descriptionenddefself.table@table||=Table.newenddefself.append(row)attr_accessor(row.key)ifrow.respond_to?(:key)self.table<<rowenddefself.options(*args,**options,&block)appendOptions.parse(*args,**options,&block)enddefself.nested(*args,**options)appendNested.new(*args,**options)enddefself.one(*args,**options)appendOne.new(*args,**options)enddefself.many(*args,**options)appendMany.new(*args,**options)enddefself.split(*args,**options)appendSplit.new(*args,**options)enddefself.usage(rows,name)rows.nested(name,self)do|rows|returnunless@table@table.rows.eachdo|row|ifrow.respond_to?(:usage)row.usage(rows)elserows<<rowendendendenddefself.command_line(name)if@table"#{name}#{@table.usage}"elsenameendenddefprint_usage(*args,output: $stderr,formatter: Output::DetailedFormatter)rows=Output::Rows.newself.class.usage(rows,*args)formatter.print(rows,output)endendend