# encoding: UTF-8 # frozen_string_literal: true require 'nrser/refinements/types' using NRSER::Types # Namespace # ======================================================================= module Locd module CLI module Command # Definitions # ======================================================================= class Agent < Locd::CLI::Command::Base desc "add [OPTIONS] -- CMD_TEMPLATE...", "Add an agent that runs a command in the current directory" example <<~END Serve Yard docs for a Ruby gem in development Defines a Yard server working in the current directory that will be available at http://yard.my_gem.test:8888 (unless Loc'd is running on a different port than 8888). locd site add --name=yard.my_gem.test -- bundle exec yard server --reload --port {port} --bind {bind} END include_options groups: [:write, :add, :respond_with_agents] def add *cmd_template, **kwds logger.trace __method__.to_s, cmd_template: cmd_template, kwds: kwds, options: options # Merge all the keywords together into the format needed to call # {Locd::Agent.add} kwds.merge! **option_kwds( :force, groups: [:write] ), cmd_template: cmd_template # Check args # `:cmd_template` can not be empty at this point if kwds[:cmd_template].empty? || kwds[:cmd_template].all?( &:empty? ) raise Thor::RequiredArgumentMissingError, "CMD_TEMPLATE argument is required to add an agent" end # Need a `:label` too unless t.non_empty_str === kwds[:label] raise Thor::RequiredArgumentMissingError, "--label=LABEL option is required to add an agent" end # Do the add agent = agent_class.add **kwds # Reload (unless we were told not to... usually you want to reload) agent.reload if options[:load] respond agent end end # /Namespace # ======================================================================= end # module Command end # module CLI end # module Locd