App-Cme

 view release on metacpan or  search on metacpan

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

    return;
}

sub opt_spec {
    my ( $class, $app ) = @_;
    return ( 
        [ "backup:s"  => "Create a backup of configuration files before saving." ],
        [ "commit|c:s" => "commit change with message passed as argument" ],
        $class->cme_global_options,
    );
}

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

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

sub commit ($self, $msg) {
    system(qw/git commit -a -m/, $msg) == 0
        or die "git commit failed: $?\n";
    return;
}

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

    $opt->{_verbose} = 'Loader' if $opt->{verbose};

    my $stashed;

    # stash pending work
    if ($opt->{commit}) {
        $stashed = $self->autostash;
    }

    my ($model, $inst, $root) = $self->init_cme($opt,$args);

    # needed to create write_back subs
    if ($opt->{save} and not @$args) {
        $root->dump_tree();
    }

    $root->load("@$args");

    $root->deep_check; # consistency check

    if ($inst->needs_save or $opt->{save}) {
        $self->save($inst,$opt) ;

        if ($opt->{commit}) {
            $self->commit($opt->{commit});
        }
    }
    elsif (not $opt->{quiet}) {
        say "No change were applied";
    }

    if ($stashed) {
        $self->pop_stash;
    }

    return;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

App::Cme::Command::modify - Modify the configuration of an application

=head1 VERSION

version 1.048

=head1 SYNOPSIS

  # modify configuration with command line
  cme modify dpkg source 'format="(3.0) quilt"'

=head1 DESCRIPTION

Modify a configuration file with the values passed on the command line.
These command must follow the syntax defined in L<Config::Model::Loader>
(which is similar to the output of L<cme dump|"/dump"> command)

Example:

   cme modify dpkg 'control source format="(3.0) quilt"'
   cme modify ssh 'Host:"*.debian.org" User=dod'

Finding the right instructions to perform a modification may be
difficult when starting from scratch.

To get started, you can run C<cme dump --format cml> command to get
the content of your configuration in the syntax accepted by C<cme modify>:

 $ cme dump ssh -format cml
 Host:"*" -
 Host:"alioth.debian.org"
   User=dod -
 Host:"*.debian.org"
   IdentityFile:="~/.ssh/id_debian"
   User=dod -

Then you can use this output to create instruction for a modification:

 $  cme modify ssh 'Host:"*" User=dod'
 Changes applied to ssh configuration:
 - Host:"*" User has new value: 'dod'



( run in 2.208 seconds using v1.01-cache-2.11-cpan-d7f47b0818f )