lib/locd/cli/command/proxy.rb in locd-0.1.12 vs lib/locd/cli/command/proxy.rb in locd-0.1.13
- old
+ new
@@ -1,37 +1,48 @@
+# encoding: UTF-8
# frozen_string_literal: true
+
# Requirements
# =======================================================================
-# Stdlib
-# -----------------------------------------------------------------------
+### Stdlib ###
+
require 'shellwords'
-# Deps
-# -----------------------------------------------------------------------
+### Deps ###
+
require 'thor'
-# Project / Package
-# -----------------------------------------------------------------------
+### Project / Package ###
+require_relative './agent'
+
# 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 Locd::CLI::Command::Proxy < Locd::CLI::Command::Agent
+class Proxy < Agent
# Helpers
# ============================================================================
#
@@ -50,11 +61,11 @@
if proxy.nil?
logger.error "Proxy agent plist not found",
expected_path: Locd::Agent::Proxy.plist_abs_path.to_s
- logger.info "Run `locd setup` to create it."
+ logger.info "Run `locd proxy add` to create it."
exit 1
end
proxy
@@ -63,35 +74,41 @@
# end protected
public
-
# Commands
# ============================================================================
desc "add",
"Add agents that runs a command in the current directory"
- include_options groups: [:write, :add, :respond_with_agents]
+
+ include_shared t[ groups: t.HasAny( :add,
+ :respond_with_agents ) ]
+
+ include_shared t[ groups: :write, name: t.Not( :label ) ]
+
def add
agent = agent_class.add **option_kwds( groups: :write )
logger.info "`#{ agent.label }` agent created."
- agent.load if options[:load]
+ agent.reload if options[:load]
respond agent
end
desc "run",
"Run the proxy server (in the foreground)"
+
method_option :bind,
desc: "Address to bind the proxy server to",
aliases: ['-b', '--host', '-h'],
type: :string,
default: Locd.config[:proxy, :bind]
+
method_option :port,
desc: "Port to run the proxy on",
aliases: '-p',
type: :numeric,
default: Locd.config[:proxy, :port]
@@ -102,10 +119,11 @@
end
desc "port",
"Get port Loc'd proxy is running on or configured for"
+
def port
respond Locd::Proxy.port
end
@@ -143,35 +161,41 @@
end
desc "start",
"Start the proxy"
- option :write,
- desc: "Set `launchd` *Disabled* key to `false`",
- type: :boolean
+ include_shared t[ groups: :start ]
def start
- proxy.start **option_kwds( :write )
+ proxy.start **option_kwds( groups: :start )
end
desc "stop",
"Stop the proxy"
- include_options groups: [:stop]
+ include_shared t[ groups: :stop ]
option :write,
desc: "Set `launchd` *Disabled* key to `true`",
type: :boolean
def stop
- proxy.stop **option_kwds( :unload, groups: :stop )
+ proxy.stop **option_kwds( groups: :stop )
end
desc "restart",
"Restart the proxy"
- include_options groups: [:stop]
+ include_shared t[ groups: t.HasAny( :start, :stop ) ]
option :write,
desc: "Set `launchd` *Disabled* key to `false`",
type: :boolean
def restart
- proxy.restart **option_kwds( :write, groups: :stop )
+ proxy.restart **option_kwds( groups: [ :start, :stop ] )
end
-end # module Locd::CLI::Proxy
+end # class Proxy
+
+
+# /Namespace
+# ============================================================================
+
+end # module Command
+end # module CLI
+end # module Locd