File Coverage

blib/lib/App/Cme/Command/fix.pm
Criterion Covered Total %
statement 17 40 42.5
branch 0 6 0.0
condition n/a
subroutine 6 11 54.5
pod 5 5 100.0
total 28 62 45.1


line stmt bran cond sub pod time code
1             #
2             # This file is part of App-Cme
3             #
4             # This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             # ABSTRACT: Fix the configuration of an application
11              
12             $App::Cme::Command::fix::VERSION = '1.038';
13             use strict;
14 1     1   604 use warnings;
  1         2  
  1         25  
15 1     1   5 use 5.10.1;
  1         1  
  1         20  
16 1     1   7  
  1         3  
17             use App::Cme -command ;
18 1     1   5  
  1         1  
  1         6  
19             use base qw/App::Cme::Common/;
20 1     1   264  
  1         2  
  1         80  
21             use Config::Model::ObjTreeScanner;
22 1     1   6  
  1         3  
  1         301  
23             my ($self, $opt, $args) = @_;
24             $self->check_unknown_args($args);
25 0     0 1   $self->process_args($opt,$args);
26 0           return;
27 0           }
28 0            
29             my ( $class, $app ) = @_;
30             return (
31             [ "from=s@" => "fix only a subset of a configuration tree" ],
32 0     0 1   [ "backup:s" => "Create a backup of configuration files before saving." ],
33             [ "filter=s" => "pattern to select the element name to be fixed"],
34 0           $class->cme_global_options,
35             );
36             }
37              
38             my ($self) = @_;
39             my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
40             return "$desc [application] [ file ]";
41             }
42 0     0 1    
43 0           my ($self) = @_;
44 0           return $self->get_documentation;
45             }
46              
47             my ($self, $opt, $args) = @_;
48 0     0 1    
49 0           my ($model, $inst, $root) = $self->init_cme($opt,$args);
50              
51             my @fix_from = $opt->{from} ? @{$opt->{from}} : ('') ;
52              
53 0     0 1   foreach my $path (@fix_from) {
54             my $node_to_fix = $inst->config_root->grab($path);
55 0           my $msg = "cme: running fix on ".$inst->name." configuration";
56             $msg .= "from node ". $node_to_fix->name if $path;
57 0 0         say $msg. "..." if $opt->{verbose};
  0            
58             $node_to_fix->apply_fixes($opt->{fix_filter});
59 0           }
60 0            
61 0           $self->save($inst,$opt) ;
62 0 0         return;
63 0 0         }
64 0            
65             1;
66              
67 0            
68 0           =pod
69              
70             =encoding UTF-8
71              
72             =head1 NAME
73              
74             App::Cme::Command::fix - Fix the configuration of an application
75              
76             =head1 VERSION
77              
78             version 1.038
79              
80             =head1 SYNOPSIS
81              
82             # fix dpkg (this example requires Config::Model::Dpkg)
83             cme fix dpkg
84              
85             =head1 DESCRIPTION
86              
87             Checks the content of the configuration file of an application (and
88             show warnings if needed), update deprecated parameters (old value are
89             saved to new parameters) and fix warnings are fixed. The configuration
90             is saved if anything was changed. If no changes are done, the file is
91             not saved.
92              
93             =head1 Common options
94              
95             See L<cme/"Global Options">.
96              
97             =head1 options
98              
99             =over
100              
101             =item from
102              
103             Use option C<-from> to fix only a subset of a configuration tree. Example:
104              
105             cme fix dpkg -from 'control binary:foo Depends'
106              
107             This option can be repeated:
108              
109             cme fix dpkg -from 'control binary:foo Depends' -from 'control source Build-Depends'
110              
111             =item filter
112              
113             Filter the leaf according to a pattern. The pattern is applied to the element name to be fixed
114             Example:
115              
116             cme fix dpkg -from control -filter Build # will fix all Build-Depends and Build-Depend-Indep
117              
118             or
119              
120             cme fix dpkg -filter Depend
121              
122             =back
123              
124             =head1 SEE ALSO
125              
126             L<cme>, L<App::Cme::Command::migrate>
127              
128             =head1 AUTHOR
129              
130             Dominique Dumont
131              
132             =head1 COPYRIGHT AND LICENSE
133              
134             This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>.
135              
136             This is free software, licensed under:
137              
138             The GNU Lesser General Public License, Version 2.1, February 1999
139              
140             =cut