Class: Tweemux::Action::Forward

Inherits:
Tweemux::Action show all
Defined in:
lib/tweemux/action/forward.rb

Instance Method Summary collapse

Methods inherited from Tweemux::Action

#call, colorize_tmux_command, explain, #explained_run, explained_run, #explained_run_as, explained_run_as, highlight_command, highlight_explanation, #initialize, load_all!, pseudo_restarts, system_or_raise, tmux_S, #tmux_S

Constructor Details

This class inherits a constructor from Tweemux::Action

Instance Method Details

#colored_sample_commandObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/tweemux/action/forward.rb', line 19

def colored_sample_command
  [
    'forward'.color(:keyword),
    'local'.color(:host),
    '22'.color(:number),
    'from'.color(:keyword),
    'sharpsaw.org'.color(:host),
    '3322'.color(:number),
  ].join ' '
end

#is_int?(str) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/tweemux/action/forward.rb', line 30

def is_int? str
  str.to_i.to_s == str
end

#run(args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/tweemux/action/forward.rb', line 2

def run args
  usage_fail 'wrong number of thingies' unless 5 == args.size
  host, hostport, from_, remote_host, port = args
  usage_fail 'third thingy has to be numeric port' unless is_int? hostport
  usage_fail 'fourth thingy has to be "from"' unless 'from' == from_
  usage_fail 'fith thingy has to be numeric port' unless is_int? port
  host = 'localhost' if 'local' == host
  explained_run %W(ssh -fNR #{port}:#{host}:#{hostport} #{remote_host}),
    '-f = background, -N = no remote command, -R = remote forward'
end

#usage_fail(what_happened) ⇒ Object

Raises:



13
14
15
16
17
# File 'lib/tweemux/action/forward.rb', line 13

def usage_fail what_happened
  raise FunkyUsage,
    (what_happened+". Expected usage:\n  ").color(:error_explanation) + 
    'tweemux '.color(:keyword) + colored_sample_command
end