# frozen_string_literal: true # Requirements # ======================================================================= # Stdlib # ----------------------------------------------------------------------- # Deps # ----------------------------------------------------------------------- # Project / Package # ----------------------------------------------------------------------- # Refinements # ======================================================================= require 'nrser/refinements/types' using NRSER::Types # Namespace # ======================================================================= module Locd module CLI module Command # Definitions # ======================================================================= # CLI interface using the `thor` gem. # # @see http://whatisthor.com/ # class Agent < Base # Shared Options # ============================================================================ def_shared :option, name: :long, groups: :respond_with_agents, group: "Display", desc: "Display agent details table", aliases: 'l', type: :boolean # `:pattern` Group # ---------------------------------------------------------------------------- # # Options when provided a `PATTERN` argument used to find agents by label. # def_shared :argument, name: :pattern, groups: :pattern, desc: "Label or workdir pattern to find agent(s)", type: :string, required: false, complete: ->( klass:, **etc ) { klass.agent_class.labels.to_a } def_shared :option, name: :full, groups: :pattern, group: "Pattern", desc: "Require label PATTERN to match entire string", aliases: [ '-u', ], type: :boolean def_shared :option, name: :ignore_case, groups: :pattern, group: "Pattern", desc: "Make label PATTERN case-insensitive", aliases: [ 'i' ], type: :boolean def_shared :option, name: :recursive, groups: :pattern, group: "Pattern", desc: "Make workdir PATTERN match all subdirs too", aliases: [ 'r' ], type: :boolean # NOTE We don't expose the workdir pattern's `:cwd` option... # If you want to match a directory from the CLI, just provide that # directory... no reason to specify the `:cwd` in an option then # provide a relative PATTERN # # `:multi` Group # ---------------------------------------------------------------------------- # # For commands that can match multiple agents. # def_shared :option, name: :all, groups: :multi, group: "Pattern", desc: "Apply to ALL agents that PATTERN matches", aliases: [ 'a' ], type: :boolean # `:write` Group # ---------------------------------------------------------------------------- # # Options when writing an agent `.plist` (`create`, `update`). # def_shared :option, name: :label, groups: :write, desc: "Agent label, which is also the domain the proxy will serve it at", aliases: [ '--name', '-n' ], type: :string, required: true def_shared :option, name: :workdir, groups: :write, desc: "Working directory for the agent's command", aliases: [ '--dir' ], type: :string def_shared :option, name: :log_path, groups: :write, desc: "Path to log agent's STDOUT and STDERR (combined)", aliases: [ '--log' ], type: :string def_shared :option, name: :keep_alive, groups: :write, desc: "Try to keep the agent running", type: :boolean, default: false def_shared :option, name: :run_at_load, groups: :write, desc: "Start the agent when loading it", type: :boolean, default: false # `:add` Group # ---------------------------------------------------------------------------- def_shared :option, name: :force, groups: :add, group: "Add", desc: "Overwrite any existing agent", type: :boolean, default: false def_shared :option, name: :load, groups: :add, group: "Add", desc: "Load the agent into `launchd`", type: :boolean, default: true # `:start` Group # -------------------------------------------------------------------------- # # Relevant options when starting agents. # def_shared :option, name: :load, groups: :start, group: "Start", desc: "Load the agent before starting", type: :boolean, default: true def_shared :option, name: :force, groups: :start, group: "Start", desc: "Force loading of agent even if it's disabled", type: :boolean, default: false def_shared :option, name: :enable, groups: :start, group: "Start", desc: "Set `launchd` *Disabled* key to `false`", type: :boolean, default: false # `:stop` Group # -------------------------------------------------------------------------- # # Relevant options when stopping agents. # def_shared :option, name: :unload, groups: :stop, group: "Stop", desc: "Unload the agent from `launchd` after stopping", type: :boolean, default: true def_shared :option, name: :disable, groups: :stop, group: "Stop", desc: "Set `launchd` *Disabled* key to `true`", type: :boolean, default: false # `:restart` Group # -------------------------------------------------------------------------- # # Relevant options when stopping agents. # def_shared :option, name: :reload, groups: :restart, group: "Restart", desc: "Unload and reload the agent in `launchd`", type: :boolean, default: true end # class Locd::CLI::Command::Agent # /Namespace # ======================================================================= end # module Command end # module CLI end # module Locd