App-Cme

 view release on metacpan or  search on metacpan

lib/App/Cme/Command/check.pm  view on Meta::CPAN

#
# This file is part of App-Cme
#
# This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>.
#
# This is free software, licensed under:
#
#   The GNU Lesser General Public License, Version 2.1, February 1999
#
# ABSTRACT: Check the configuration of an application

package App::Cme::Command::check ;
$App::Cme::Command::check::VERSION = '1.048';
use strict;
use warnings;
use 5.10.1;

use App::Cme -command ;

use base qw/App::Cme::Common/;

use Config::Model::ObjTreeScanner;

sub validate_args {
    my ($self, $opt, $args) = @_;

    $self->check_unknown_args($args);
    $self->process_args($opt,$args);
    return;
}

sub opt_spec {
    my ( $class, $app ) = @_;
    return ( 
        [ "strict!" => "cme will exit 1 if warnings are found during check" ],
        $class->cme_global_options,
    );
}

sub usage_desc {
  my ($self) = @_;
  my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
  return "$desc [application]  [ config_file ]";
}

sub description {
    my ($self) = @_;
    return $self->get_documentation;
}

sub execute {
    my ($self, $opt, $args) = @_;

    my ($model, $inst, $root) = $self->init_cme($opt,$args);
    my $check =  $opt->{force_load} ? 'no' : 'yes' ;
    say "Loading data..." if $opt->{verbose};

    Config::Model::ObjTreeScanner->new(
        leaf_cb => sub { },
        check => $check,
    )->scan_node( undef, $root );

    say "Checking data.." if $opt->{verbose};
    $root->dump_tree( mode => 'full' ); # light check (value per value)
    $root->deep_check; # consistency check
    say "Check done." if $opt->{verbose};

    my $ouch = $inst->has_warning;

    if ( $ouch ) {
        my $app = $inst->application;
        warn "you can try 'cme fix $app' to fix the warnings shown above\n";
        die "Found $ouch warnings in strict mode\n" if $opt->{strict};
    }

    return;
}

1;

__END__

=pod



( run in 0.793 second using v1.01-cache-2.11-cpan-140bd7fdf52 )