# frozen_string_literal: true # Requirements # ======================================================================= # Stdlib # ----------------------------------------------------------------------- require 'shellwords' # Deps # ----------------------------------------------------------------------- require 'thor' # Project / Package # ----------------------------------------------------------------------- # Refinements # ======================================================================= require 'nrser/refinements/types' using NRSER::Types # Namespace # ======================================================================= module Locd module CLI module Command # Definitions # ======================================================================= # Manage log rotation. # class RotateLogs < Job # Helpers # ============================================================================ # def self.agent_class Locd::Agent::RotateLogs end protected # ======================================================================== def agent @agent ||= begin agent = agent_class.get if agent.nil? logger.error "Agent plist not found", expected_path: agent_class.plist_abs_path.to_s logger.info "Run `locd setup` to create it." exit 1 end agent end end def find_only! pattern; agent; end def find_multi! pattern; [ agent ]; end # end protected public # Commands # ============================================================================ require_relative './rotate_logs/add' desc "run", "Rotate agent logs using `newsyslog`" def run_ Locd::Newsyslog.run_all end # Agent Interface # ---------------------------------------------------------------------------- desc "plist", "Show the agent's launchd property list" def plist if options[:json] || options[:yaml] respond agent.plist else respond agent.path.read end end desc "start", "Start the agent" option :write, desc: "Set `launchd` *Disabled* key to `false`", type: :boolean def start agent.start **option_kwds( :write ) end desc "stop", "Stop the agent" include_shared t[ groups: :stop ] option :write, desc: "Set `launchd` *Disabled* key to `true`", type: :boolean def stop agent.stop **option_kwds( :unload, groups: :stop ) end desc "restart", "Restart the agent" include_shared t[ groups: :stop ] option :write, desc: "Set `launchd` *Disabled* key to `false`", type: :boolean def restart agent.restart **option_kwds( :write, groups: :stop ) end end # module Locd::CLI::RotateLogs # /Namespace # ======================================================================== end # module Command end # module CLI end # module Locd