#!/usr/bin/env ruby # encoding: utf-8 $LOAD_PATH <<::File.expand_path('../../lib', __FILE__) require 'local_pac' module LocalPac module Cli class Main < Thor class_option :config_file, type: :string, desc: 'Config file' class_option :log_level, type: :string, desc: 'Log level for ui logging' class_option :debug, type: :boolean, default: false, desc: 'Run application in debug mode' no_commands { include LocalPac::Cli::Helper } desc 'serve', 'Serve pacfiles' option :access_log, type: :string, desc: 'File to write access log to' option :listen, type: :string, default: 'tcp://localhost:8000', desc: 'Listen for requests' option :rack_environment, type: :string, default: 'production', desc: 'Rack environment for application' def serve LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file] LocalPac.config.access_log = options[:access_log] if options[:access_log] LocalPac.config.lock set_log_level(options[:log_level]) set_debug(options[:debug]) LocalPac.ui_logger.debug('Options: ' + options.to_s) LocalPac.ui_logger.debug("Config:\n" + LocalPac.config.to_s) Server.new(options[:listen], options[:rack_environment]).start end desc 'init', 'Create files/directories to use local_pac in dir or $PWD' option :force, type: :boolean, default: false, desc: 'Overwrite existing files?' option :pre_seed, type: :boolean, default: false, desc: 'Add some example files to git repository' def init LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file] LocalPac.config.lock set_log_level(options[:log_level]) set_debug(options[:debug]) LocalPac.ui_logger.debug('Options: ' + options.to_s) LocalPac.ui_logger.debug("Config:\n" + LocalPac.config.to_s) Initializer.new(force: options[:force], pre_seed: options[:pre_seed]).run end desc 'status', 'Show status of local_pac: configuration, known proxy pacs, server running etc.' def status LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file] LocalPac.config.lock set_log_level(options[:log_level]) set_debug(options[:debug]) ApplicationStatus.new.show end desc 'reload', 'Reload configuration, local storage etc.' option :pid_file, type: :string, desc: 'Pid file of daemon' subcommand 'reload', LocalPac::Cli::Reload end end end LocalPac::Cli::Main.start