class Canals::Cli::Application

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/canals/cli.rb, line 18
def initialize(*args)
  super
  startup_checks
end

Public Instance Methods

__print_version() click to toggle source
# File lib/canals/cli.rb, line 24
def __print_version
  say "Canals version #{Canals::VERSION}"
end
adhoc(remote_host, remote_port, local_port=nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/canals/cli.rb, line 95
def restart(name)
  trestart(name)
end
socks(local_port) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/canals/cli.rb, line 90
def stop(name)
  tstop(name)
end
update(name) click to toggle source
# 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