Class: WireGuard::Admin::CLI

Inherits:
Thor
  • Object
show all
Extended by:
ClassHelpers
Includes:
InstanceHelpers
Defined in:
lib/wire_guard/admin/cli.rb

Overview

Provides all the commands

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassHelpers

default_network, path, repository

Methods included from InstanceHelpers

#ip, #network, #repository

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/wire_guard/admin/cli.rb', line 27

def self.exit_on_failure?
  true
end

Instance Method Details

#config(name) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wire_guard/admin/cli.rb', line 51

def config(name)
  warn "Using database #{repository.path}" if options[:verbose]
  peer = repository.find_peer(network, name)
  case peer
  when Server
    puts Templates::Server.new(
      server: peer,
      network: network,
      clients: repository.clients(network)
    ).render
  when Client
    puts Templates::Client.new(
      client: peer,
      network: network,
      servers: repository.servers(network)
    ).render
  else
    raise "No template defined for #{peer}"
  end
rescue StandardError => e
  raise Thor::Error, "Error: #{e.message}"
end