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, #startup_checks, #trestart, #tstart, #tstop
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
#create(name, remote_host, remote_port, local_port = nil) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/canals/cli.rb', line 27
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
|
#repo ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/canals/cli.rb', line 76
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
68
69
70
|
# File 'lib/canals/cli.rb', line 68
def restart(name)
trestart(name)
end
|
#start(name) ⇒ Object
58
59
60
|
# File 'lib/canals/cli.rb', line 58
def start(name)
tstart(name)
end
|
#stop(name) ⇒ Object
63
64
65
|
# File 'lib/canals/cli.rb', line 63
def stop(name)
tstop(name)
end
|
#update(name) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/canals/cli.rb', line 41
def update(name)
tunnel = Canals.repository.get(name)
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
|