class Locd::CLI::Command::Proxy

CLI interface using the `thor` gem.

@see whatisthor.com/

Public Class Methods

agent_class() click to toggle source

Helpers

# File lib/locd/cli/command/proxy.rb, line 50
def self.agent_class
  Locd::Agent::Proxy
end

Public Instance Methods

add() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 90
def add
  agent = agent_class.add **option_kwds( groups: :write )
  
  logger.info "`#{ agent.label }` agent created."
  
  agent.reload if options[:load]
  
  respond agent
end
plist() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 153
def plist
  agent = proxy
  
  if options[:json] || options[:yaml]
    respond agent.plist
  else
    respond agent.path.read
  end
end
port() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 125
def port
  respond Locd::Proxy.port
end
restart() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 189
def restart
  proxy.restart **option_kwds( groups: [ :start, :stop ] )
end
rm() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 146
def rm
  proxy.remove
end
run_() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 115
def run_
  Locd::Proxy.serve \
    bind: options[:bind],
    port: options[:port]
end
start() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 167
def start
  proxy.start **option_kwds( groups: :start )
end
status() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 135
def status
  respond \
    label:  proxy.label,
    port:   proxy.port,
    status: proxy.status
end
stop() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 178
def stop
  proxy.stop **option_kwds( groups: :stop )
end

Protected Instance Methods

proxy() click to toggle source
# File lib/locd/cli/command/proxy.rb, line 58
def proxy
  @proxy ||= begin
    proxy = Locd::Agent::Proxy.get
    
    if proxy.nil?
      logger.error "Proxy agent plist not found",
        expected_path: Locd::Agent::Proxy.plist_abs_path.to_s
        
      logger.info "Run `locd proxy add` to create it."
      
      exit 1
    end
    
    proxy
  end
end