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