Class: AgentsControl::CLI
- Inherits:
-
Thor
- Object
- Thor
- AgentsControl::CLI
- Defined in:
- lib/agents_control/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #console ⇒ Object
- #daemon ⇒ Object
- #doctor ⇒ Object
- #hooks(subcommand = "status") ⇒ Object
- #service(subcommand = "status") ⇒ Object
- #sessions ⇒ Object
- #setup ⇒ Object
- #stop ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
8 |
# File 'lib/agents_control/cli.rb', line 8 def self.exit_on_failure? = true |
Instance Method Details
#console ⇒ Object
19 |
# File 'lib/agents_control/cli.rb', line 19 def console = Console.new(config: config, store: store, secrets: secrets).run |
#daemon ⇒ Object
79 |
# File 'lib/agents_control/cli.rb', line 79 def daemon = Daemon.new(config: config, store: store, secrets: secrets).run |
#doctor ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/agents_control/cli.rb', line 118 def doctor checks = Doctor.new(config: config, secrets: secrets).run checks.each do |check| colour = { ok: :green, warn: :yellow, fail: :red }[check.status] say("#{check.icon} #{check.name.ljust(22)} #{check.detail}", colour) say(" └ #{check.fix}", :white) if check.fix end broken = checks.count(&:failed?) say("") say(broken.zero? ? "Everything checks out." : "Not okay: #{broken}", broken.zero? ? :green : :red) end |
#hooks(subcommand = "status") ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/agents_control/cli.rb', line 82 def hooks(subcommand = "status") case subcommand when "install" then hooks_install when "uninstall" then hooks_uninstall when "status" then hooks_status else say("I don't know the subcommand #{subcommand}. Try install, uninstall, status.", :red) end end |
#service(subcommand = "status") ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/agents_control/cli.rb', line 134 def service(subcommand = "status") unit = Service.for_platform case subcommand when "install" say("Installed #{unit.install}", :green) say("Ruby: #{unit.ruby}", :white) say("Log: #{unit.log_path}", :white) when "uninstall" then unit.uninstall && say("Autostart removed", :green) else say(unit.installed? ? "Autostart configured: #{unit.path}" : "Autostart not configured") end end |
#sessions ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/agents_control/cli.rb', line 31 def sessions registry = Registry.new list = [:all] ? registry.sessions : registry.agents if list.empty? say([:all] ? "No tabs found." : "No live agent sessions.", :yellow) say("Available backends: #{backend_names(registry)}", :white) return end print_table_of(list) say("") say("Total: #{list.size} · backends: #{backend_names(registry)}", :white) end |
#setup ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/agents_control/cli.rb', line 56 def setup token = ask_token return if token.nil? || !valid_shape?(token) api = Api.new(token) me = verify(api) return unless me secrets.set(:telegram_token, token) say("Token saved: #{secrets.target.name}", :green) publish_commands(api) capture_chat_id(api, me) end |
#stop ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/agents_control/cli.rb', line 96 def stop port = config.get("hooks.port", Daemon::DEFAULT_PORT).to_i # argv array, not a shell string: no reason to trust a shell to # parse a port number pulled from config. out, = Open3.capture3("lsof", "-nP", "-iTCP:#{port}", "-sTCP:LISTEN", "-t") pids = out.split return say("Nothing is running.", :yellow) if pids.empty? pids.each do |pid| Process.kill("TERM", pid.to_i) say("Stopped #{pid}", :green) rescue Errno::ESRCH, Errno::EPERM => e say("Couldn't stop #{pid}: #{e.}", :red) end end |
#version ⇒ Object
148 |
# File 'lib/agents_control/cli.rb', line 148 def version = say(AgentsControl::VERSION) |