Class: Portless::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/portless/cli.rb

Overview

Hand-rolled command dispatch (no Thor/optparse ceremony, like portless's cli.ts). rb-portless run <cmd> is the main path; the rest manage the proxy, CA trust, hosts file, and diagnostics.

Constant Summary collapse

COMMANDS =
%w[run proxy trust hosts list doctor clean prune alias get service].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



14
15
16
# File 'lib/portless/cli.rb', line 14

def initialize(argv)
  @argv = argv.dup
end

Class Method Details

.start(argv = ARGV) ⇒ Object



10
11
12
# File 'lib/portless/cli.rb', line 10

def self.start(argv = ARGV)
  new(argv).run
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/portless/cli.rb', line 18

def run
  return print_version if flag?("--version", "-v")
  return print_help if @argv.empty? || flag?("--help", "-h")

  command = @argv.first
  command = "run" unless COMMANDS.include?(command)
  send("cmd_#{command}", rest(command))
rescue Portless::NonInteractiveError => e
  warn "rb-portless: #{e.message}"
  exit 2
rescue Portless::Error => e
  warn "rb-portless: #{e.message}"
  exit 1
end