App-Cme
view release on metacpan or search on metacpan
contrib/bash_completion.cme view on Meta::CPAN
_cme_commands()
{
# use perl so that plugged in subcommand (like meta) are listed
SUBCMDS=$(perl -MApp::Cme -e'print join("\n", grep {not /-/} App::Cme->new->command_names);')
COMPREPLY=( $( compgen -W "$SUBCMDS" -- $cur ) )
}
_cme_cmd_run()
{
vendor_scripts=$(perl -MConfig::Model::Lister -E 'my $p = $INC{"Config/Model/Lister.pm"}; $p =~ s/Lister.pm/scripts/; say $p')
if [[ $COMP_CWORD -eq 2 ]] ; then
scripts=$(find ~/.cme/scripts/ /etc/cme/scripts $vendor_scripts -type f ! -name '*~' -printf '%f\n' 2>/dev/null)
COMPREPLY=( $( compgen -W "-list $scripts" -- $cur ) )
elif [[ $prev == '-arg' ]]; then
script=$(find ~/.cme/scripts/ /etc/cme/scripts $vendor_scripts -type f -name ${COMP_WORDS[2]})
var=$( perl -E 'my @v; while(<>) { push @v, /\$(\w+)/g }; my %map = map { ($_ => 1)} @v; print map { "$_= " } sort keys %map;' $script);
COMPREPLY=( $( compgen -W "$var" -- $cur ) )
elif [[ $prev != '-list' ]]; then
COMPREPLY=( $( compgen -W "--arg --doc --commit --no-commit --cat $global_options" -- $cur ) )
fi
lib/App/Cme/Command/check.pm view on Meta::CPAN
sub description {
my ($self) = @_;
return $self->get_documentation;
}
sub execute {
my ($self, $opt, $args) = @_;
my ($model, $inst, $root) = $self->init_cme($opt,$args);
my $check = $opt->{force_load} ? 'no' : 'yes' ;
say "Loading data..." if $opt->{verbose};
Config::Model::ObjTreeScanner->new(
leaf_cb => sub { },
check => $check,
)->scan_node( undef, $root );
say "Checking data.." if $opt->{verbose};
$root->dump_tree( mode => 'full' ); # light check (value per value)
$root->deep_check; # consistency check
say "Check done." if $opt->{verbose};
my $ouch = $inst->has_warning;
if ( $ouch ) {
my $app = $inst->application;
warn "you can try 'cme fix $app' to fix the warnings shown above\n";
die "Found $ouch warnings in strict mode\n" if $opt->{strict};
}
return;
lib/App/Cme/Command/fix.pm view on Meta::CPAN
my ($self, $opt, $args) = @_;
my ($model, $inst, $root) = $self->init_cme($opt,$args);
my @fix_from = $opt->{from} ? @{$opt->{from}} : ('') ;
foreach my $path (@fix_from) {
my $node_to_fix = $inst->config_root->grab($path);
my $msg = "cme: running fix on ".$inst->name." configuration";
$msg .= "from node ". $node_to_fix->name if $path;
say $msg. "..." if $opt->{verbose};
$node_to_fix->apply_fixes($opt->{fix_filter});
}
$self->save($inst,$opt) ;
return;
}
1;
__END__
lib/App/Cme/Command/modify.pm view on Meta::CPAN
$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;
lib/App/Cme/Command/run.pm view on Meta::CPAN
return $self->get_documentation;
}
sub check_script_arguments ($self, $opt, $script_name) {
if ($opt->{list} or not $script_name) {
my @scripts;
foreach my $path ( @script_paths ) {
next unless $path->is_dir;
push @scripts, map {$_->basename} grep { ! /~$/ } $path->children();
}
say $opt->{list} ? "Available scripts:" : "Missing script argument. Choose one of:";
foreach my $script_path (sort @scripts) {
my ($file, $data) = $self->get_script_data($script_path);
my $app_info = $data->{app} ? sprintf(" (app %s)", $data->{app}) : "";
printf("- %s%s\n",$script_path, $app_info );
}
say "";
say "Run 'cme run <script> -doc' to get more details on a script.";
return 0;
}
return 1;
}
sub find_script_file ($self, $script_name) {
my $script;
if ($script_name =~ m!/!) {
$script = path($script_name);
}
lib/App/Cme/Command/run.pm view on Meta::CPAN
my ($script_file, $script_data) = $self->get_script_data($script_name, $opt);
if ($opt->{cat}) {
print $script_file->slurp_utf8;
return;
}
my $commit_msg = $script_data->{commit_msg};
if ($opt->doc) {
say join "\n", $script_data->{doc}->@*;
say "will commit with message: '$commit_msg'" if $commit_msg;
return;
}
if (not defined $script_data->{app}) {
$self->run_script_as_code ($script_name, $script_file);
return;
}
if (my @missing = sort keys $script_data->{missing}->%*) {
die "Error: Missing variables '". join("', '",@missing)
lib/App/Cme/Command/run.pm view on Meta::CPAN
my @dirs = map { chomp; split /\s+/; }
($opt->{foreach} eq '-' ? <STDIN> : ($opt->{foreach}));
my $start = path('.')->absolute;
foreach my $d (@dirs) {
my $t_dir = $start->child($d);
if (not $t_dir->is_dir) {
die "Cannot run script in $d: not a directory\n";
}
say "Running script in $t_dir ...";
# instance is stored in Config::Model, so the name must be changed
$opt->{instance_name} = $d;
# instance is persisted in $self, so its ref must be removed
delete $self->{_instance};
chdir $t_dir->stringify;
$self->run_script ($opt, $app_args, $script_data, {%user_args});
# once we're done, remove instance from Model to avoid memory leaks
$self->{_model}->delete_instance($d);
}
lib/App/Cme/Command/run.pm view on Meta::CPAN
$self->save($inst,$opt) ;
# commit if needed
if ($commit_msg and not $opt->{no_commit}) {
my $processed_msg = $self->process_commit_message(
$root, $script_data->{values}, $commit_msg
);
$self->commit($processed_msg);
}
} else {
say "No change were applied";
}
if ($stashed) {
$self->pop_stash;
}
return;
}
lib/App/Cme/Command/update.pm view on Meta::CPAN
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";
}
# remove undef values or empty strings. Literal '0' are not
# expected here
say join("\n", grep {$_} @msgs );
if ($opt->{edit}) {
$self->run_tk_ui ( $inst, $opt);
}
else {
$self->save($inst,$opt) ;
}
return;
}
t/cme-command.t view on Meta::CPAN
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/;
foreach my $d (@t_dirs) {
$d->remove_tree;
$d->mkdir;
}
my @test_cmd = (qw!run t/lib/Config/Model/scripts/cme-test!,
( run in 2.222 seconds using v1.01-cache-2.11-cpan-d7a12ab2c7f )