| 1 | #!/usr/local/bin/perl | ||
| 2 | # PODNAME: eris-field-lookup.pl | ||
| 3 | # ABSTRACT: Utility for testing the logging contextualizer | ||
| 4 | ## no critic (RequireEndWithOne) | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use CLI::Helpers qw(:output); | ||
| 9 | use Data::Printer; | ||
| 10 | use Getopt::Long::Descriptive; | ||
| 11 | use YAML; | ||
| 12 | use eris::dictionary; | ||
| 13 | |||
| 14 | #------------------------------------------------------------------------# | ||
| 15 | # Argument Parsing | ||
| 16 | my ($opt,$usage) = describe_options( | ||
| 17 | "%c %o <fields to lookup>", | ||
| 18 | [ 'list|l', "list all available fields" ], | ||
| 19 | [], | ||
| 20 | [ 'config|c=s', "eris config file", { | ||
| 21 | callbacks => { exists => sub { -f shift } } | ||
| 22 | }], | ||
| 23 | [], | ||
| 24 | ['help', 'Display this help', { shortcircuit => 1 }], | ||
| 25 | ); | ||
| 26 | if( $opt->help ) { | ||
| 27 | print $usage->text; | ||
| 28 | exit 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | #------------------------------------------------------------------------# | ||
| 32 | # Main | ||
| 33 | my $cfg = $opt->config ? YAML::LoadFile($opt->config) : {}; | ||
| 34 | my %args = exists $cfg->{dictionary} && ref $cfg->{dictionary} eq 'HASH' ? %{ $cfg->{dictionary} } : (); | ||
| 35 | my $dict = eris::dictionary->new(%args); | ||
| 36 | |||
| 37 | if( $opt->list ) { | ||
| 38 | my $fields = $dict->fields; | ||
| 39 | output({color=>'cyan'}, sprintf "Found %d fields in the dictionary.", scalar(keys %{ $fields })); | ||
| 40 | foreach my $f (sort keys %{ $fields }) { | ||
| 41 | my $F = $dict->lookup($f); | ||
| 42 | output({indent=>1}, sprintf "%s (%s) %s", $f, $fields->{$f}, $F->{description}); | ||
| 43 | } | ||
| 44 | exit 0; | ||
| 45 | } | ||
| 46 | |||
| 47 | die $usage->text unless @ARGV; | ||
| 48 | foreach my $field (@ARGV) { | ||
| 49 | output({clear=>1,color=>'yellow'}, "Looking up '$field'"); | ||
| 50 | p( $dict->lookup($field) ); | ||
| 51 | } | ||
| 52 | |||
| 53 | __END__ | ||
| 54 | |||
| 55 | =pod | ||
| 56 | |||
| 57 | =encoding UTF-8 | ||
| 58 | |||
| 59 | =head1 NAME | ||
| 60 | |||
| 61 | eris-field-lookup.pl - Utility for testing the logging contextualizer | ||
| 62 | |||
| 63 | =head1 VERSION | ||
| 64 | |||
| 65 | version 0.008 | ||
| 66 | |||
| 67 | =head1 AUTHOR | ||
| 68 | |||
| 69 | Brad Lhotsky <brad@divisionbyzero.net> | ||
| 70 | |||
| 71 | =head1 COPYRIGHT AND LICENSE | ||
| 72 | |||
| 73 | This software is Copyright (c) 2015 by Brad Lhotsky. | ||
| 74 | |||
| 75 | This is free software, licensed under: | ||
| 76 | |||
| 77 | The (three-clause) BSD License | ||
| 78 | |||
| 79 | =cut |