From 801e58ca2787157c17f1d23826530757b5d2cad2 Mon Sep 17 00:00:00 2001 From: Glenn Date: Fri, 24 Mar 2023 16:53:27 +0100 Subject: [PATCH] feat: prepare for future commands --- src/{launcher.cr => builder/builder.cr} | 16 ++++++++++++- src/cli.cr | 32 +++++++++++++++---------- src/planner/planner.cr | 11 +++++++++ src/scaffolder/scaffolder.cr | 12 ++++++++++ 4 files changed, 57 insertions(+), 14 deletions(-) rename src/{launcher.cr => builder/builder.cr} (91%) create mode 100644 src/planner/planner.cr create mode 100644 src/scaffolder/scaffolder.cr diff --git a/src/launcher.cr b/src/builder/builder.cr similarity index 91% rename from src/launcher.cr rename to src/builder/builder.cr index 9e06b66..e7c5d74 100644 --- a/src/launcher.cr +++ b/src/builder/builder.cr @@ -1,6 +1,6 @@ module DocMachine - class Launcher + class Builder def initialize(config) @basedir = config[:data_dir]? ? config[:data_dir] : Dir.current @basehash = Digest::SHA256.hexdigest(@basedir)[0..6] @@ -120,5 +120,19 @@ module DocMachine def docker_opts() end + + def self.add_options(opts) + opts.on("build", "Build content and produce deliverables") do + opts.banner = [ + "Usage: #{PROGRAM_NAME} build [options]", + "", + "Main options:" + ].join("\n") + + opts.separator "" + opts.separator "Builder Options:" + opts.on("-t", "--test", "Test") { puts "Test" } + end + end end end diff --git a/src/cli.cr b/src/cli.cr index 038addf..cacc236 100644 --- a/src/cli.cr +++ b/src/cli.cr @@ -2,7 +2,9 @@ require "option_parser" require "digest/sha256" require "colorize" -require "./launcher" +require "./builder/builder.cr" +require "./scaffolder/scaffolder.cr" +require "./planner/planner.cr" module DocMachine class Cli @@ -13,7 +15,11 @@ module DocMachine options = {} of Symbol => String parser = OptionParser.new do |opts| - opts.banner = "Usage: script.cr [options]" + opts.banner = [ + "Usage: #{PROGRAM_NAME} [options]", + "", + "Main options:" + ].join("\n") opts.on("-d", "--data-dir DIR", "Content directory") do |dir| options[:data_dir] = dir @@ -35,6 +41,12 @@ module DocMachine puts opts exit end + + opts.separator "" + opts.separator "Commands:" + DocMachine::Builder.add_options(opts) + DocMachine::Scaffolder.add_options(opts) + DocMachine::Planner.add_options(opts) end parser.parse(ARGV) @@ -47,20 +59,14 @@ module DocMachine 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" + puts parser.to_s exit end - launcher = DocMachine::Launcher.new(options) - launcher.prepare - launcher.start - launcher.wait + builder = DocMachine::Builder.new(options) + builder.prepare + builder.start + builder.wait end end end diff --git a/src/planner/planner.cr b/src/planner/planner.cr new file mode 100644 index 0000000..ffce06e --- /dev/null +++ b/src/planner/planner.cr @@ -0,0 +1,11 @@ + +module DocMachine + class Planner + def self.add_options(opts) + opts.on("content", "Generate content and structure") do + opts.banner = "Usage: #{PROGRAM_NAME} plan [options]" + opts.on("-t", "--test", "Test") { puts "Test" } + end + end + end +end diff --git a/src/scaffolder/scaffolder.cr b/src/scaffolder/scaffolder.cr new file mode 100644 index 0000000..72df864 --- /dev/null +++ b/src/scaffolder/scaffolder.cr @@ -0,0 +1,12 @@ + +module DocMachine + class Scaffolder + def self.add_options(opts) + opts.on("scaffold", "Scaffold directory") do + opts.banner = "Usage: #{PROGRAM_NAME} scaffold [options]" + + opts.on("-t", "--test", "Test") { puts "Test" } + end + end + end +end