# encoding: UTF-8 # frozen_string_literal: true # Requirements # ============================================================================ ### Project / Package ### require_relative './agent' # Refinements # ======================================================================= require 'nrser/refinements/types' using NRSER::Types # Namespace # ======================================================================= module Locd module CLI module Command # Definitions # ======================================================================= # TODO Doc me pls # class Job < Agent # Helpers # ============================================================================ # def self.agent_class Locd::Agent::Job end def self.parse_every_option value case value when /\A\d+\z/, /\A\d+s\z/ value.to_i when /\A\d+m\z/ value[0...-1].to_i * 60 when /\A\d+h\z/ value[0...-1].to_i * 60 * 60 when /\A\d+d\z/ value[0...-1].to_i * 60 * 60 * 24 else raise ArgumentError, "Can't parse `every` option value: #{ value.inspect }" end end protected # ======================================================================== def agent_table agents Locd::CLI::Table.build do |t| t.col "PID", &:pid t.col "LEC", desc: "Last Exit Code", &:last_exit_code t.col "File" do |agent| agent_file agent end t.rows agents end end def get_start_interval if options[:every] && options[:at] raise Thor::ConflictingArgumentError, "Don't supply both `every` and `at` options" end start_interval = if options[:every] self.class.parse_every_option options[:every] elsif options[:at] options[:at].map { |key, value| [key.to_sym, value.to_i] }.to_h else raise Thor::RequiredArgumentMissingError, "Must provide `every` or `at` option" end logger.debug "Parsed start interval", start_interval: start_interval start_interval end # end protected public # Commands # ============================================================================ require_relative './job/add' end # class Job # /Namespace # ======================================================================= end # module Command end # module CLI end # module Locd