diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-03-11 12:04:11 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-03-11 14:10:47 +0200 |
commit | 7c9b40ce18e396b68fb45a7add1eeeecfa4b892c (patch) | |
tree | fa8f1aaeb1ae497b414ef2c72f947de4a0fb987e | |
parent | da4c5a335f0637315b94271e35532aaba0d4c794 (diff) | |
download | mangemanche-7c9b40ce18e396b68fb45a7add1eeeecfa4b892c.tar.gz mangemanche-7c9b40ce18e396b68fb45a7add1eeeecfa4b892c.tar.bz2 |
* lib/App/Mangemanche/Command/inspect.pm (run): Implement per-keyword
printers.
-rw-r--r-- | lib/App/Mangemanche/Command/inspect.pm | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/App/Mangemanche/Command/inspect.pm b/lib/App/Mangemanche/Command/inspect.pm index 24b8df9..d5a62a3 100644 --- a/lib/App/Mangemanche/Command/inspect.pm +++ b/lib/App/Mangemanche/Command/inspect.pm @@ -4,6 +4,32 @@ use warnings; use parent 'App::Mangemanche::Command'; use App::Mangemanche::Command ':exit_codes'; +sub iplist_dumper { + my ($self, $kw, $val) = @_; + print "$kw <<EOF\n"; + foreach my $ip (@$val) { + print " $ip\n"; + } + print "EOF\n"; +} + +sub auth_dumper { + my ($self, $kw, $val) = @_; + foreach my $s (@$val) { + print "$kw $s->{type} $s->{method}"; + if ($s->{'passwd-file'}) { + print " $s->{'passwd-file'} $s->{realm}"; + } + print "\n"; + } +} + +my %kwdump = ( + 'ip-list' => \&iplist_dumper, + 'trusted-ip' => \&iplist_dumper, + 'auth' => \&auth_dumper + ); + sub run { my $self = shift; $self->SUPER::run; @@ -16,19 +42,17 @@ sub run { foreach my $kw (sort keys %$cfg) { my $val = $cfg->{$kw} or next; - print "$kw "; - if (ref($val) eq 'ARRAY') { - print "<<EOF\n"; - foreach my $ip (@$val) { - print " $ip\n"; - } - print "EOF"; + if (my $d = $kwdump{$kw}) { + $self->${ \$d }($kw, $val); + } elsif (ref($val) eq 'ARRAY') { + print "# $kw " . JSON::encode_json($val) . "\n"; } elsif (JSON::is_bool($val)) { + print "$kw "; print $val ? "on" : "off"; + print "\n"; } else { - print $val + print "$kw $val\n"; } - print "\n"; } } |