| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/usr/bin/env perl
- # PODNAME: tpsgi-config
- # ABSTRACT: Print a value from the tPSGI configuration, for shell scripts
- package TPSGI::ConfigTool;
- use 5.040;
- use warnings FATAL => 'all';
- use re '/aa';
- use FindBin::libs;
- use Getopt::Long qw{GetOptionsFromArray};
- use TPSGI;
- =head1 USAGE
- tpsgi-config --KEY
- Print the value of KEY in F<~/.tpsgi.ini>, or its default, one line for each
- value when it has several. The keys are the ones that L<TPSGI> documents, and
- C<log_dir> and C<log_name>, which are made from them. It dies when no key is
- passed.
- =cut
- sub main {
- my @args = @_;
- my %config = TPSGI::get_config();
- my @params = keys(%config);
- my ( %def, %options );
- @def{@params} = map { \$options{$_} } @params;
- GetOptionsFromArray( \@args, %def );
- foreach my $param ( keys(%def) ) {
- next unless $options{$param};
- my @to_print;
- @to_print = ref $config{$param} eq 'ARRAY' ? @{ $config{$param} } : $config{$param};
- foreach my $line (@to_print) {
- print "$line\n";
- }
- return 0;
- }
- die "Must pass at least one option";
- }
- exit main(@ARGV) unless caller;
- 1;
|