From 995b9a8db11ee09bf127ca0edfdcbda6e1d45f7f Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Sun, 25 May 2008 12:53:48 +0200 Subject: [PATCH] Factor out cli_get_port function --- dowkd.in | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) 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; -- 2.11.4.GIT