From: Florian Weimer Date: Sun, 25 May 2008 10:53:48 +0000 (+0200) Subject: Factor out cli_get_port function X-Git-Url: https://repo.or.cz/w/dowkd.git/commitdiff_plain/995b9a8db11ee09bf127ca0edfdcbda6e1d45f7f Factor out cli_get_port function --- diff --git a/dowkd.in b/dowkd.in index 10e9b04..8212b84 100644 --- a/dowkd.in +++ b/dowkd.in @@ -501,6 +501,22 @@ sub from_etc () { } } +sub cli_get_port (\@$) { + my ($args, $port) = @_; + if ($args && @$args) { + if ($args->[0] eq '-p') { + shift @$args; + if (@$args) { + $port = shift @$args; + } + } elsif ($args->[0] =~ /-p(\d+)/) { + $port = $1; + shift @$args; + } + } + return $port; +} + if (@ARGV && $ARGV[0] eq '-c') { shift @ARGV; $db_file = shift @ARGV if @ARGV; @@ -513,20 +529,7 @@ if (@ARGV) { from_any_file $name; } } elsif ($cmd eq 'host') { - unless (@ARGV) { - help; - exit 1; - } - my $port = 22; - if ($ARGV[0] eq '-p') { - shift @ARGV; - if (@ARGV) { - $port = shift @ARGV; - } - } elsif ($ARGV[0] =~ /-p(\d+)/) { - $port = $1; - shift @ARGV; - } + my $port = cli_get_port @ARGV, 22; unless (@ARGV) { help; exit 1;