#!/usr/bin/env ruby # frozen_string_literal: true lib = File.expand_path('../lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'thor' require 'logger' require 'quicken' require 'quicken/cli/init' require 'quicken/commands/autoloader' LOGGER = Logger.new(STDOUT) LOGGER.level = Logger::WARN LOGGER.formatter = proc { |severity, datetime, progname, msg| "#{severity} [#{datetime}] - [#{progname.upcase}] #{msg}\n" } module Quicken class App < Thor class_option :debug, type: :boolean, aliases: [:d] option :version, type: :boolean, aliases: [:v] no_commands do def version puts "Quicken #{Quicken::VERSION}" end end def initialize *args super LOGGER.level = Logger::DEBUG if options.debug? end register Quicken::CLI::Init, :init, 'init', 'Initialize a new recipe' option :recipe, type: :string, aliases: [:f] desc 'create', 'Create a new project based on a recipe' def create recipe = options.recipe || './recipe.yml' cmd = Quicken::Commands::Run.call recipe handle_errors cmd.errors unless cmd.success? end default_command :help private def handle_errors errors errors.each { |error| LOGGER.error(error[0]) { error[1] } } end end end Quicken::App.start ARGV