CfgPrinter.pm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # ------------------------------------------------------------------------------
  2. # (C) Crown copyright Met Office. All rights reserved.
  3. # For further details please refer to the file COPYRIGHT.txt
  4. # which you should have received as part of this distribution.
  5. # ------------------------------------------------------------------------------
  6. use strict;
  7. use warnings;
  8. package Fcm::CLI::Invoker::CfgPrinter;
  9. use base qw{Fcm::CLI::Invoker};
  10. use Carp qw{croak};
  11. use Fcm::Exception;
  12. use Fcm::CfgFile;
  13. use Fcm::Config;
  14. ################################################################################
  15. # Invokes the sub-system
  16. sub invoke {
  17. my ($self) = @_;
  18. my ($cfg_file) = $self->get_arguments();
  19. if (!$cfg_file) {
  20. croak(Fcm::CLI::Exception->new({message => 'no CFGFILE specified'}));
  21. }
  22. my $cfg = Fcm::CfgFile->new(SRC => $cfg_file);
  23. Fcm::Config->instance()->verbose(0); # suppress message printing to STDOUT
  24. my $read = $cfg->read_cfg();
  25. if (!$read) {
  26. croak(Fcm::Exception->new({message => sprintf(
  27. "% :cannot read", $cfg_file,
  28. )}));
  29. }
  30. $cfg->print_cfg($self->get_options()->{output});
  31. }
  32. 1;
  33. __END__
  34. =head1 NAME
  35. Fcm::CLI::Invoker::CfgPrinter
  36. =head1 SYNOPSIS
  37. use Fcm::CLI::Invoker::CfgPrinter;
  38. $invoker = Fcm::CLI::Invoker::CfgPrinter->new({
  39. command => $command,
  40. options => \%options,
  41. arguments => $arguments,
  42. });
  43. $invoker->invoke();
  44. =head1 DESCRIPTION
  45. This class extends L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> an inherits all its
  46. methods. An object of this class is used to invoke the pretty printer for FCM
  47. configuration files.
  48. =head1 METHODS
  49. See L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> for a list of inherited methods.
  50. =over 4
  51. =item invoke()
  52. Invokes the pretty printer for a FCM configuration file.
  53. If the I<output> option is set, output goes to the location specified by this
  54. value. Otherwise, it prints to STDOUT.
  55. =back
  56. =head1 DIAGNOSTICS
  57. =over 4
  58. =item L<Fcm::Exception|Fcm::Exception>
  59. The invoke() method can croak() with this exception if the configuration file
  60. cannot be read.
  61. =item L<Fcm::CLI::Exception|Fcm::CLI::Exception>
  62. The invoke() method can croak() with this exception if no configuration file is
  63. specified.
  64. =back
  65. =head1 TO DO
  66. Unit tests.
  67. =head1 SEE ALSO
  68. L<Fcm::CfgFile|Fcm::CfgFile>,
  69. L<Fcm::CLI::Exception|Fcm::CLI::Exception>,
  70. L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>,
  71. L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand>
  72. =head1 COPYRIGHT
  73. E<169> Crown copyright Met Office. All rights reserved.
  74. =cut