class Samovar::Command

def self.append(row)

def self.append(row)
	attr_accessor(row.key) if row.respond_to?(:key)
	
	self.table << row
end

def self.command_line(name)

def self.command_line(name)
	if @table
		"#{name} #{@table.usage}"
	else
		name
	end
end

def self.many(*args, **options)

def self.many(*args, **options)
	append Many.new(*args, **options)
end

def self.nested(*args, **options)

def self.nested(*args, **options)
	append Nested.new(*args, **options)
end

def self.one(*args, **options)

def self.one(*args, **options)
	append One.new(*args, **options)
end

def self.options(*args, **options, &block)

def self.options(*args, **options, &block)
	append Options.parse(*args, **options, &block)
end

def self.parse(input)

def self.parse(input)
	command = self.new(input)
	
	raise IncompleteParse.new("Could not parse #{input}") unless input.empty?
	
	return command
end

def self.split(*args, **options)

def self.split(*args, **options)
	append Split.new(*args, **options)
end

def self.table

def self.table
	@table ||= Table.new
end

def self.usage(rows, name)

def self.usage(rows, name)
	rows.nested(name, self) do |rows|
		return unless @table
		
		@table.rows.each do |row|
			if row.respond_to?(:usage)
				row.usage(rows)
			else
				rows << row
			end
		end
	end
end

def [] key

def [] key
	@attributes[key]
end

def initialize(input = nil)

def initialize(input = nil)
	self.class.table.parse(input) do |key, value|
		self.send("#{key}=", value)
	end if input
end

def log_system(args, options)

def log_system(args, options)
	# Print out something half-decent:
	command_line = Shellwords.join(args)
	puts Rainbow(command_line).color(:blue)
end

def print_usage(*args, output: $stderr, formatter: Output::DetailedFormatter)

def print_usage(*args, output: $stderr, formatter: Output::DetailedFormatter)
	rows = Output::Rows.new
	
	self.class.usage(rows, *args)
	
	formatter.print(rows, output)
end

def system(*args, **options)

def system(*args, **options)
	log_system(args, options)
	
	Kernel::system(*args, **options)
rescue Errno::ENOENT
	return false
end

def system!(*args, **options)

def system!(*args, **options)
	if system(*args, **options)
		return true
	else
		raise SystemError.new("Command #{args.first.inspect} failed: #{$?.to_s}")
	end
end

def track_time

def track_time
	start_time = Time.now
	
	yield
ensure
	end_time = Time.now
	elapsed_time = end_time - start_time
	
	$stdout.flush
	$stderr.puts Rainbow("Elapsed Time: %0.3fs" % elapsed_time).magenta
end