tpsgi-config 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env perl
  2. # PODNAME: tpsgi-config
  3. # ABSTRACT: Print a value from the tPSGI configuration, for shell scripts
  4. package TPSGI::ConfigTool;
  5. use 5.040;
  6. use warnings FATAL => 'all';
  7. use re '/aasx';
  8. use FindBin::libs;
  9. use Getopt::Long qw{GetOptionsFromArray};
  10. use TPSGI;
  11. =head1 USAGE
  12. tpsgi-config --KEY
  13. Print the value of KEY in F<~/.tpsgi.ini>, or its default, one line for each
  14. value when it has several. The keys are the ones that L<TPSGI> documents, and
  15. C<log_dir> and C<log_name>, which are made from them. It dies when no key is
  16. passed.
  17. =cut
  18. sub main {
  19. my @args = @_;
  20. my %config = TPSGI::get_config();
  21. my @params = keys(%config);
  22. my ( %def, %options );
  23. @def{@params} = map { \$options{$_} } @params;
  24. GetOptionsFromArray( \@args, %def );
  25. foreach my $param ( keys(%def) ) {
  26. next unless $options{$param};
  27. my @to_print;
  28. @to_print = ref $config{$param} eq 'ARRAY' ? @{ $config{$param} } : $config{$param};
  29. foreach my $line (@to_print) {
  30. print "$line\n";
  31. }
  32. return 0;
  33. }
  34. die "Must pass at least one option";
  35. }
  36. exit main(@ARGV) unless caller;
  37. 1;