67 lines
1.7 KiB
Crystal
67 lines
1.7 KiB
Crystal
|
require "option_parser"
|
||
|
require "digest/sha256"
|
||
|
require "colorize"
|
||
|
|
||
|
require "./launcher"
|
||
|
|
||
|
module DocMachine
|
||
|
class Cli
|
||
|
def initialize
|
||
|
end
|
||
|
|
||
|
def start(argv)
|
||
|
options = {} of Symbol => String
|
||
|
|
||
|
parser = OptionParser.new do |opts|
|
||
|
opts.banner = "Usage: script.cr [options]"
|
||
|
|
||
|
opts.on("-d", "--data-dir DIR", "Content directory") do |dir|
|
||
|
options[:data_dir] = dir
|
||
|
end
|
||
|
|
||
|
opts.on("-a", "--action ACTION", "Action (watch, build, shell, etc.)") do |action|
|
||
|
options[:action] = action
|
||
|
end
|
||
|
|
||
|
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do |tty|
|
||
|
options[:tty] = tty
|
||
|
end
|
||
|
|
||
|
opts.on("-v", "--verbose", "Enable verbosity") do |verbose|
|
||
|
options[:verbose] = true.to_s
|
||
|
end
|
||
|
|
||
|
opts.on("-h", "--help", "Show this help") do
|
||
|
puts opts
|
||
|
exit
|
||
|
end
|
||
|
end
|
||
|
|
||
|
parser.parse(ARGV)
|
||
|
|
||
|
|
||
|
basedir = options[:data_dir]? ? options[:data_dir] : Dir.current
|
||
|
basehash = Digest::SHA256.hexdigest(basedir)[0..6]
|
||
|
action = options[:action]? ? options[:action] : "watch"
|
||
|
verbosity = options[:verbose]? ? options[:verbose] : 0
|
||
|
docker_image = "glenux/docmachine:latest"
|
||
|
|
||
|
if options[:help]?
|
||
|
puts "Usage: script.cr [options]"
|
||
|
puts ""
|
||
|
puts "-d, --data-dir DIR Content directory"
|
||
|
puts "-a, --action ACTION Action (watch, build, shell, etc.)"
|
||
|
puts "-t, --tty Enable TTY mode (needed for shell)"
|
||
|
puts "-v, --verbose Enable verbosity"
|
||
|
puts "-h, --help Show this help"
|
||
|
exit
|
||
|
end
|
||
|
|
||
|
launcher = DocMachine::Launcher.new(options)
|
||
|
launcher.prepare
|
||
|
launcher.start
|
||
|
launcher.wait
|
||
|
end
|
||
|
end
|
||
|
end
|