view release on metacpan or search on metacpan
* can now specify default value for script args
Other bug fixes:
* run: remove warning about Log4Perl initialisation
* run: fix option description
* cme: update Log4Perl init in doc
1.023 2017-09-10
Bug fixes:
* add missing backup option to read/write commands (like cme edit,
fix, modify ...)
* die if both require_config_file and require_backend_argument are set
in app file (in Config/Model/[system|user|application].d)
1.022 2017-06-21
Bug fixes for smoke test failures:
* test failure exit code to be != 0
* work-around test issue with perl < 5,18
=item -force-load
Load file even if error are found in data. Bad data are discarded
=item -canonical
Write config data back using model order. By default, write items back
using the order found in the configuration file. This feature is
experimental and not supported by all backends.
=item -backup
Create a backup of configuration files before saving. By default, C<old> will
be appended to the backup file. I.e. C<foo.conf> will be backed up as C<foo.conf.old>.
You can specify an alternate suffix. For instance C<-backup dpkg-old>.
=item -save
Force a save even if no change was done. Useful to reformat the configuration file.
=item -strict
When set, cme will exit 1 if warnings are found during check (of left after fix)
=item -verbose
contrib/bash_completion.cme view on Meta::CPAN
COMPREPLY=( $( compgen -W "$global_options --fuse-dir --dfuse --dir-char" -- $cur ) )
;;
migrate)
COMPREPLY=( $( compgen -W "$global_options" -- $cur ) )
;;
update)
COMPREPLY=( $( compgen -W "$global_options" -- $cur ) )
;;
# modify completion could be much more elaborate...
modify)
COMPREPLY=( $( compgen -W "$global_options --save --backup --format" -- $cur ) )
;;
run)
COMPREPLY=( $( compgen -W "$global_options --doc --cat --no-commit" -- $cur ) )
;;
search)
COMPREPLY=( $( compgen -W "$global_options --search --narrow-search" -- $cur ) )
;;
esac
esac
fi
lib/App/Cme/Command/edit.pm view on Meta::CPAN
my ($self, $opt, $args) = @_;
$self->check_unknown_args($args);
$self->process_args($opt,$args);
return;
}
sub opt_spec {
my ( $class, $app ) = @_;
return (
[ "ui|if=s" => "user interface type. Either tk, curses, shell" ],
[ "backup:s" => "Create a backup of configuration files before saving." ],
[ "open-item=s" => "open a specific item of the configuration" ],
$class->cme_global_options,
);
}
sub usage_desc {
my ($self) = @_;
my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
return "$desc [application] [ file ] [ -ui tk|curses|shell ] [ -open-item xxx ] ";
}
lib/App/Cme/Command/fix.pm view on Meta::CPAN
my ($self, $opt, $args) = @_;
$self->check_unknown_args($args);
$self->process_args($opt,$args);
return;
}
sub opt_spec {
my ( $class, $app ) = @_;
return (
[ "from=s@" => "fix only a subset of a configuration tree" ],
[ "backup:s" => "Create a backup of configuration files before saving." ],
[ "filter=s" => "pattern to select the element name to be fixed"],
$class->cme_global_options,
);
}
sub usage_desc {
my ($self) = @_;
my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
return "$desc [application] [ file ]";
}
lib/App/Cme/Command/fusefs.pm view on Meta::CPAN
sub opt_spec {
my ( $class, $app ) = @_;
return (
[
"fuse-dir=s" => "Directory where the virtual file system will be mounted",
{required => 1}
],
[ "dfuse!" => "debug fuse problems" ],
[ "dir-char=s" => "string to replace '/' in configuration parameter names"],
[ "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 ] -fuse-dir xxx [ -dir-char x ] ";
}
lib/App/Cme/Command/migrate.pm view on Meta::CPAN
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 (
[ "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 ]";
}
lib/App/Cme/Command/modify.pm view on Meta::CPAN
$self->check_unknown_args($args);
$self->process_args($opt,$args);
$self->usage_error("No modification instructions given on command line")
unless @$args or $opt->{save};
return;
}
sub opt_spec {
my ( $class, $app ) = @_;
return (
[ "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 ] instructions";
}
lib/App/Cme/Command/run.pm view on Meta::CPAN
"$home/.cme/scripts",
"/etc/cme/scripts/",
);
push @script_paths, path($INC{"Config/Model.pm"})->parent->child("Model/scripts") ;
sub opt_spec {
my ( $class, $app ) = @_;
return (
[ "arg=s@" => "script argument. run 'cme run <script> -doc' for possible arguments" ],
[ "backup:s" => "Create a backup of configuration files before saving." ],
[ "foreach=s" => "Run script in several directories. The list of directories "
. "must be passed as a single argument, i.e. --foreach 'foo bar'" ],
[ "commit|c:s" => "commit change with passed message" ],
[ "cat" => "Show the script file" ],
[ "no-commit|nc!" => "skip commit to git" ],
[ "doc!" => "show documention of script" ],
[ "list!" => "list available scripts" ],
$class->cme_global_options,
);
}
lib/App/Cme/Command/shell.pm view on Meta::CPAN
my ($self, $opt, $args) = @_;
$self->check_unknown_args($args);
$self->process_args($opt,$args);
return;
}
sub opt_spec {
my ( $class, $app ) = @_;
return (
[ "open-item=s" => "open a specific item of the configuration" ],
[ "backup:s" => "Create a backup of configuration files before saving." ],
[ "bare!" => "run bare terminal UI"],
$class->cme_global_options,
);
}
sub usage_desc {
my ($self) = @_;
my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
return "$desc [application] [file ]";
}
lib/App/Cme/Command/update.pm view on Meta::CPAN
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 ]";
}
lib/App/Cme/Common.pm view on Meta::CPAN
root_class_name => $opt->{_root_model},
instance_name => $opt->{_application},
application => $opt->{_application},
check => $opt->{force_load} ? 'no' : 'yes',
auto_create => $opt->{create},
backend_arg => $opt->{_backend_arg},
config_file => $opt->{_config_file},
config_dir => $opt->{_config_dir},
);
foreach my $param (qw/root_dir canonical backup instance_name/) {
$instance_args{$param} = $opt->{$param} if defined $opt->{$param};
}
return $self->{_instance} ||= $self->model->instance(%instance_args);
}
sub init_cme {
my ($self, @args) = @_;
# model and inst are deleted if not kept in a scope
return ( $self->model(@args) , $self->instance(@args), $self->instance->config_root );
t/cme-command.t view on Meta::CPAN
# cleanup before tests
$wr_root -> remove_tree;
my $test1 = 'popcon1';
my $wr_dir = $wr_root->child($test1);
my $conf_dir = $wr_dir->child('/etc');
$conf_dir->mkpath;
my $conf_file = $conf_dir->child("popularity-contest.conf");
# created with -backup option
my $backup_file = $conf_dir->child("popularity-contest.conf.old");
subtest "list command" => sub {
my @test_cmd = qw/list/;
my $result = test_app( 'App::Cme' => \@test_cmd );
say "-- stdout --\n", $result->stdout,"-----" if $trace;
is($result->error, undef, 'threw no exceptions');
};
subtest "foreach option" => sub {
my @t_dirs = map {$wr_root->child($_)} qw/for1 for2 for3/;
t/cme-command.t view on Meta::CPAN
my $ok = test_app( 'App::Cme' => \@test_cmd );
is( $ok->exit_code, 0, 'all went well' ) or diag("Failed command @test_cmd");
is($ok->stderr.'', '', 'check: no log on stderr' );
is($ok->stdout.'', "Loading data...\nChecking data..\nCheck done.\n" ,
'check: got messages on stdout' );
};
subtest "minimal modification" => sub {
$conf_file->spew_utf8(@orig);
# test minimal modif (re-order)
my @test_cmd = (qw/modify popcon -save -backup -canonical -root-dir/, $wr_dir->stringify);
my $ok = test_app( 'App::Cme' => \@test_cmd );
is ($ok->exit_code, 0, 'all went well' ) or diag("Failed command cme @test_cmd");
is($ok->error, undef, 'threw no exceptions');
is($ok->stderr.'', '', 'modify: no log on stderr' );
is($ok->stdout.'', '', 'modify: no message on stdout' );
file_contents_like $conf_file->stringify, qr/cme/, "updated header";
# with perl 5.14 5.16, IO::Handle writes an extra \n with print.
my $re = $^V lt 5.18.1 ? qr/yes"\n+MY/ : qr/yes"\nMY/;
file_contents_like $conf_file->stringify, $re, "reordered file";
file_contents_unlike $conf_file->stringify, qr/removed/, "double comment is removed";
# check backup
ok($backup_file->is_file, "backup file was created");
file_contents_like $backup_file->stringify, qr/should be removed/, "backup file contains original comment";
};
subtest "modification with wrong parameter" => sub {
$conf_file->spew_utf8(@orig);
my @test_cmd = (qw/modify popcon -root-dir/, $wr_dir->stringify, qq/PARITICIPATE=yes/);
my $oops = test_app( 'App::Cme' => \@test_cmd );
isnt ($oops->exit_code, 0, 'error detected' );
like($oops->error.'' , qr/object/, 'check unknown element' );
isnt( $oops->exit_code, 0, 'wrong parameter detected' );