docmachine-cli/src/write/cli.cr

46 lines
1.1 KiB
Crystal
Raw Normal View History

2023-04-27 09:42:15 +02:00
2023-03-25 20:40:52 +01:00
require "./config"
2023-03-27 16:01:20 +02:00
require "./run"
2023-04-27 09:42:15 +02:00
require "./module"
2023-03-25 20:40:52 +01:00
module DocMachine::Write
2023-03-27 16:01:20 +02:00
class Cli
2023-04-24 18:43:04 +02:00
Log = DocMachine::Write::Log.for("cli")
2023-03-27 16:01:20 +02:00
def self.add_options(opts, args, parent_config, commands)
config = Config.new(parent_config)
2023-03-25 20:40:52 +01:00
opts.on("write", "Write content target for plan (beta)") do
2023-04-27 10:02:35 +02:00
opts.banner = "Usage: #{PROGRAM_NAME} write [options] TARGET"
2023-03-27 16:01:20 +02:00
opts.on("-f", "--force", "Don't ask for confirmation") do
config.force = true
2023-03-25 20:40:52 +01:00
end
2023-03-26 11:41:40 +02:00
2023-04-27 10:02:35 +02:00
opts.on("-t", "--template TEMPLATE", "Use given template") do |template_name|
config.template_name = template_name
end
2023-03-27 16:01:20 +02:00
commands << ->() : Nil do
2023-04-27 09:42:15 +02:00
Log.debug { "before any" }
2023-03-27 16:01:20 +02:00
if args.size < 1
2023-04-27 09:42:15 +02:00
Log.error { "No target given!" }
2023-03-27 16:01:20 +02:00
exit 1
end
config.target_directory = args[0]
2023-04-27 09:42:15 +02:00
Log.debug { "before new" }
app = DocMachine::Write::Run.new(config)
2023-04-27 09:42:15 +02:00
Log.debug { "before prepare" }
2023-03-27 16:01:20 +02:00
app.prepare
2023-04-27 09:42:15 +02:00
Log.debug { "before start" }
2023-03-27 16:01:20 +02:00
app.start
2023-04-27 09:42:15 +02:00
Log.debug { "before wait" }
2023-03-27 16:01:20 +02:00
app.wait
2023-03-26 11:41:40 +02:00
end
2023-03-25 20:40:52 +01:00
end
end
end
end