Class: Canals::Cli::Application
- Inherits:
-
Thor
- Object
- Thor
- Canals::Cli::Application
show all
- Includes:
- Helpers, Thor::Actions
- Defined in:
- lib/canals/cli.rb
Instance Method Summary
collapse
Methods included from Helpers
#check_completion, #checkmark, #startup_checks, #trestart, #tstart, #tstop, #tunnel_options
Constructor Details
Returns a new instance of Application.
18
19
20
21
|
# File 'lib/canals/cli.rb', line 18
def initialize(*args)
super
startup_checks
end
|
Instance Method Details
#__print_version ⇒ Object
24
25
26
|
# File 'lib/canals/cli.rb', line 24
def __print_version
say "Canals version #{Canals::VERSION}"
end
|
#adhoc(remote_host, remote_port, local_port = nil) ⇒ Object
132
133
134
135
136
137
|
# File 'lib/canals/cli.rb', line 132
def adhoc(remote_host, remote_port, local_port=nil)
opts = {"adhoc" => true, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => local_port}.merge(options)
opts["name"] ||= "adhoc-#{remote_host}-#{remote_port}"
opts = Canals::CanalOptions.new(opts)
tstart(opts)
end
|
#create(name, remote_host, remote_port, local_port = nil) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/canals/cli.rb', line 34
def create(name, remote_host, remote_port, local_port=nil)
opts = {name: name, remote_host: remote_host, remote_port: remote_port, local_port: local_port}.merge(options)
opts = Canals::CanalOptions.new(opts)
Canals.create_tunnel(opts)
say "Tunnel #{name.inspect} created.", :green
end
|
#delete(name) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/canals/cli.rb', line 42
def delete(name)
tunnel = Canals.repository.get(name.to_sym)
if tunnel.nil?
say "couldn't find tunnel #{name.inspect}. try using 'create' instead", :red
return
end
tstop(name, silent: true)
Canals.repository.delete(name.to_sym)
say "Tunnel #{name.inspect} deleted.", :green
end
|
#repo ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/canals/cli.rb', line 103
def repo
if Canals.repository.empty?
say "Repository is currently empty."
return
end
require 'terminal-table'
require 'canals/core_ext/string'
columns = ["name", "remote_host", "remote_port", "local_port"]
columns_extra = ["bind_address", "env_name", "user", "hostname"]
if options[:full]
columns += columns_extra
end
env = options[:env]
sort_by = options[:'sort-by'].downcase.split.join("_").to_sym
rows = Canals.repository.select { |conf| env.nil? || conf.env_name == env }
.sort { |a,b| a.send(sort_by) <=> b.send(sort_by) rescue a.name <=> b.name }
.map { |conf| columns.map{ |c| conf.send c.to_sym } }
table = Terminal::Table.new :headings => columns.map{|c| c.sub("_"," ").titleize }, :rows => rows
say table
say "* use --full to show more data", [:white, :dim] if !options[:full]
end
|
#restart(name) ⇒ Object
95
96
97
|
# File 'lib/canals/cli.rb', line 95
def restart(name)
trestart(name)
end
|
#socks(local_port) ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/canals/cli.rb', line 146
def socks(local_port)
opts = {"adhoc" => true, "socks" => true, "local_port" => local_port}.merge(options)
opts["name"] ||= "__SOCKS__"
opts = Canals::CanalOptions.new(opts)
opts.name = "SOCKS-adhoc-#{opts.hostname}-#{local_port}" if opts.name == "__SOCKS__"
tstart(opts)
end
|
#start(name) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/canals/cli.rb', line 79
def start(name)
tunnel = tunnel_options(name)
if options["local_port"]
tunnel.local_port = options["local_port"]
tunnel.name = "adhoc-#{name}-#{options["local_port"]}"
tunnel.adhoc = true
end
tstart(tunnel)
end
|
#stop(name) ⇒ Object
90
91
92
|
# File 'lib/canals/cli.rb', line 90
def stop(name)
tstop(name)
end
|
#update(name) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/canals/cli.rb', line 61
def update(name)
tunnel = Canals.repository.get(name.to_sym)
if tunnel.nil?
say "couldn't find tunnel #{name.inspect}. try using 'create' instead", :red
return
end
if options.empty?
say "you need to specify what to update. use `canal help update` to see a list of optional updates"
return
end
opts = tunnel.to_hash.merge(options)
opts = Canals::CanalOptions.new(opts)
Canals.create_tunnel(opts)
say "Tunnel #{name.inspect} updated.", :green
end
|