ssx.rb
# Extract hostname from SSH args. Search for the first argument not without
# a '-' prefix, while skipping those options that have such argument before
# the hostname: i.e. in -l username, discard 'username'.
# Expects: input parameter args to be an array of strings
# Returns: hostname or nil if didn't find one
Extract hostname from SSH args. Search for the first argument not without
a '-' prefix, while skipping those options that have such argument before
the hostname: i.e. in -l username, discard 'username'.
Expects: input parameter args to be an array of strings
Returns: hostname or nil if didn't find one
Extract hostname from SSH args . Search for the first argument not without a ' - ' prefix while skipping those options that have such argument before the hostname : i . e . in - l username discard ' username ' . Expects : input parameter args to be an array of strings Returns : hostname or nil if didn ' t find one
def extract_hostname_from_args args
  opts_with_arg = %w[b c D e F I i L l m O o p R S W w]
  a = args.dup
  while a.size > 0
    opt = a[0]
    return opt.gsub(/^\w+@/,"") unless opt.chars.first == "-"
    opt_char = opt.chars.to_a[1]
    a.shift
    if opts_with_arg.include? opt_char
      a.shift if a.size > 0
    end
  end
  nil
end
def extract_hostname_from_args args opts_with_arg = %w[ b c D e F I i L l m O o p R S W w ] a = args . dup while a . size > 0 opt = a [ 0 ] return opt . gsub ( / ^ \w +@ / , "" ) unless opt . chars . first == "-" opt_char = opt . chars . to_a [ 1 ] a . shift if opts_with_arg . include? opt_char a . shift if a . size > 0 end end nil end
Extract hostname from SSH args.
Extract hostname from SSH args .
args