Class: Codebot::Options::Network

Inherits:
Thor
  • Object
show all
Defined in:
lib/codebot/options/network.rb

Overview

A class that handles the codebot network command.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Ensures that thor uses the correct exit code.

Returns:

  • (Boolean)

    true



104
105
106
# File 'lib/codebot/options/network.rb', line 104

def self.exit_on_failure?
  true
end

.shared_authentication_optionsObject

Sets shared options for authenticating to the IRC network.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/codebot/options/network.rb', line 25

def self.shared_authentication_options
  # Not a boolean to prevent thor from generating --no-disable-sasl flag
  option :disable_sasl, type: :string, banner: '',
                        desc: 'Disable SASL authentication'
  option :sasl_username, desc: 'Set the username for SASL authentication'
  option :sasl_password, desc: 'Set the password for SASL authentication'

  option :disable_nickserv, type: :string, banner: '',
                            desc: 'Disable NickServ authentication'
  option :nickserv_username,
         desc: 'Set the username for NickServ authentication'
  option :nickserv_password,
         desc: 'Set the password for NickServ authentication'
end

.shared_connection_optionsObject

Sets shared options for connecting to the IRC network.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/codebot/options/network.rb', line 12

def self.shared_connection_options
  option :host, aliases: '-H',
                desc: 'Set the server hostname or address'
  option :port, type: :numeric, aliases: '-p',
                desc: 'Set the port to connect to'
  option :secure, type: :boolean, aliases: '-s',
                  desc: 'Connect securely using TLS'
  option :server_password, desc: 'Set the server password'
  option :nick, aliases: '-N',
                desc: 'Set the nickname'
end

.shared_propery_optionsObject

Sets shared options for specifying properties belonging to the Network class.



42
43
44
45
46
47
48
49
# File 'lib/codebot/options/network.rb', line 42

def self.shared_propery_options
  shared_connection_options
  shared_authentication_options
  option :bind, aliases: '-b',
                desc: 'Bind to the specified IP address or host'
  option :modes, aliases: '-m',
                 desc: 'Set user modes'
end

Instance Method Details

#create(name) ⇒ Object

Creates a new network with the specified name.

Parameters:

  • name (String)

    the name of the new network



57
58
59
60
61
# File 'lib/codebot/options/network.rb', line 57

def create(name)
  Options.with_core(parent_options, true) do |core|
    NetworkManager.new(core.config).create(options.merge(name: name))
  end
end

#destroy(name) ⇒ Object

Destroys the network with the specified name.

Parameters:

  • name (String)

    the name of the network



95
96
97
98
99
# File 'lib/codebot/options/network.rb', line 95

def destroy(name)
  Options.with_core(parent_options, true) do |core|
    NetworkManager.new(core.config).destroy(name, options)
  end
end

#list(search = nil) ⇒ Object

Lists all networks, or networks with names containing the given search term.

Parameters:

  • search (String, nil) (defaults to: nil)

    an optional search term



84
85
86
87
88
# File 'lib/codebot/options/network.rb', line 84

def list(search = nil)
  Options.with_core(parent_options, true) do |core|
    NetworkManager.new(core.config).list(search)
  end
end

#update(name) ⇒ Object

Updates the network with the specified name.

Parameters:

  • name (String)

    the name of the network



72
73
74
75
76
# File 'lib/codebot/options/network.rb', line 72

def update(name)
  Options.with_core(parent_options, true) do |core|
    NetworkManager.new(core.config).update(name, options)
  end
end