2023-02-21 15:06:20 +00:00
|
|
|
require "option_parser"
|
|
|
|
require "digest/sha256"
|
|
|
|
require "colorize"
|
|
|
|
|
2023-03-24 15:53:27 +00:00
|
|
|
require "./builder/builder.cr"
|
|
|
|
require "./scaffolder/scaffolder.cr"
|
|
|
|
require "./planner/planner.cr"
|
2023-02-21 15:06:20 +00:00
|
|
|
|
|
|
|
module DocMachine
|
|
|
|
class Cli
|
|
|
|
def initialize
|
|
|
|
end
|
|
|
|
|
|
|
|
def start(argv)
|
|
|
|
options = {} of Symbol => String
|
|
|
|
|
|
|
|
parser = OptionParser.new do |opts|
|
2023-03-24 15:53:27 +00:00
|
|
|
opts.banner = [
|
|
|
|
"Usage: #{PROGRAM_NAME} [options]",
|
|
|
|
"",
|
|
|
|
"Main options:"
|
|
|
|
].join("\n")
|
2023-02-21 15:06:20 +00:00
|
|
|
|
|
|
|
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
|
2023-03-24 15:53:27 +00:00
|
|
|
|
|
|
|
opts.separator ""
|
|
|
|
opts.separator "Commands:"
|
|
|
|
DocMachine::Builder.add_options(opts)
|
|
|
|
DocMachine::Scaffolder.add_options(opts)
|
|
|
|
DocMachine::Planner.add_options(opts)
|
2023-02-21 15:06:20 +00:00
|
|
|
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]?
|
2023-03-24 15:53:27 +00:00
|
|
|
puts parser.to_s
|
2023-02-21 15:06:20 +00:00
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2023-03-24 15:53:27 +00:00
|
|
|
builder = DocMachine::Builder.new(options)
|
|
|
|
builder.prepare
|
|
|
|
builder.start
|
|
|
|
builder.wait
|
2023-02-21 15:06:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|