# encoding: UTF-8 # frozen_string_literal: true # Refinements # ======================================================================= require 'nrser/refinements/types' using NRSER::Types # Definitions # ======================================================================= # Manage Agent definitions attached to projects. # module Locd module CLI module Command class Project < Base # Instance Methods # ======================================================================== # @!group Command Instance Methods # -------------------------------------------------------------------------- desc 'load', "Load project Agent definitions" option :file, aliases: [ 'f' ], type: :string, default: './dev/locd.yaml' def load file_path = options[:file].to_pn.expand_path unless file_path.file? raise "Definition file not found at `#{ file_path }`" end defs = YAML.load( file_path.read ).with_indifferent_access t.hash_( keys: t.in(%w{agents sites jobs}), ).check! defs { agents: Locd::Agent, sites: Locd::Agent::Site, jobs: Locd::Agent::Job, }.each do |key, agent_class| if defs.key? key logger.info "Adding or updating #{ key }..." defs[key].each do |label, values| logger.info payload: { values: values, options: values.to_options, } method, agent = agent_class.add_or_update \ label: label, **values. map { |key, value| key = key.gsub '-', '_' if key == 'cmd_template' value = value.squish end [ key, value ] }. to_h. to_options action = t.match method, :add, 'added', :update, 'updated' logger.info "Agent `#{ label }` #{ action }" end # each label, values end # if defs.key? key end # each key, agent_class end # @!endgroup Command Instance Methods # ************************************ end; end; end; end # class Locd::CLI::Command::Site