1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
# ABSTRACT: Update the configuration of an application
package App::Cme::Command::update ;
use strict;
use warnings;
use 5.10.1;
use App::Cme -command ;
use base qw/App::Cme::Common/;
use Config::Model::ObjTreeScanner;
use Config::Model;
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 (
[ "edit!" => "Run editor after update is done" ],
[ "backup:s" => "Create a backup of configuration files before saving." ],
$class->cme_global_options,
);
}
sub usage_desc {
my ($self) = @_;
my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
return "$desc [application] [file ]";
}
sub description {
my ($self) = @_;
return $self->get_documentation;
}
sub execute {
my ($self, $opt, $args) = @_;
my ( $inst) = $self->instance($opt,$args);
say "Updating data..." unless $opt->{quiet};
my @msgs = $inst->update(quiet => $opt->{quiet});
if (@msgs and not $opt->{quiet}) {
say "Update done";
}
elsif (not $opt->{quiet}) {
say "Command done, but ".$opt->{_application}
. " model has no provision for update";
}
if ($opt->{edit}) {
say join("\n", grep {defined $_} @msgs );
$self->run_tk_ui ( $inst, $opt);
}
else {
$self->save($inst,$opt) ;
say join("\n", grep {defined $_} @msgs );
}
return;
}
1;
__END__
=head1 SYNOPSIS
cme update <application>
# example: cme update dpkg-copyright
=head1 DESCRIPTION
Update a configuration file. The update is done scanning external
resource.
For instance, C<cme update dpkg-copyright> command can be used to
update a specific Debian package file (C<debian/copyright>). This is
done by scanning the headers of source files.
Currently, only dpkg-copyright application currently supports updates.
The configuration data (i.e. the content of C<debian/copyright> in
this example) is mapped to a tree structure inside L<cme>. You can:
=over 4
=item *
view this structure in YAML format by running C<cme dump dpkg-copyright>
=item *
view this structure in Config::Model's format (aka C<cml>) by running
C<cme dump -format cml dpkg-copyright>. This format is documented in
L<Config::Model::Loader>.
=item *
get a graphical view with C<cme edit dpkg-copyright>.
=back
=head1 Common options
See L<cme/"Global Options">.
=head1 options
=over
=item -open-item
Open a specific item of the configuration when opening the editor
=back
=head1 SEE ALSO
L<cme>
=cut
|