require "colorize" require "option_parser" require "file_utils" require "./quadruplet.cr" require "./backends.cr" # Not currently used. Waiting for API updates. #require "baguette-crystal-base" # Prototyping for the next generation of baguette-crystal-base. class Baguette::Configuration property application_name : String def initialize(@application_name) end end module Baguette::Log def info(text) STDOUT << (":: ".colorize :blue) << (text.colorize :white) << "\n" end def warn(text) STDERR << (":: ".colorize :yellow) << (text.colorize :yellow) << "\n" end def error(text) STDERR << (":: ".colorize :red) << (text.colorize :red) << "\n" end end module Baguette::Base getter configuration : Configuration include Baguette::Log end class OptionParser def to_s(io : IO) : Nil if banner = @banner io << banner << '\n' end @flags.select(&.starts_with? " -").join io, '\n' io << "\ncommands:\n" @flags.select{ |x| !x.starts_with? " -" }.join io, '\n' end end Colorize.on_tty_only! # CAUTION # backends: storage, ??? # rootfs templates class RootFS::Context include Baguette::Base def initialize @configuration = Baguette::Configuration.new "rootfs" end def run options_parser = uninitialized OptionParser commands = { :new => ->(args : Array(String)){ RootFS.new args[1], args[0] }, :save => ->(args : Array(String)){ RootFS.load(args[0]).save(args[1]) }, :restore => ->(args : Array(String)){ RootFS.load(args[0]).restore(args[1]) }, :mount => ->(args : Array(String)){ RootFS.load(args[0]).mount(args[1]?) }, :unmount => ->(args : Array(String)){ RootFS.load(args[0]).unmount(args[1]?) } } command = nil arguments = uninitialized Array(String) options_parser = OptionParser.parse do |parser| parser.banner = "usage: #{@configuration.application_name} [options]" parser.on "new", "Creates a new rootfs." do parser.banner = "usage: #{@configuration.application_name} new