Skip to content

Commit

Permalink
added --role as data type for apply
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed May 11, 2012
1 parent 5c97ce6 commit 6b5dc84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/Pantry/App/Command.pm
Expand Up @@ -222,9 +222,10 @@ HERE

sub data_options {
return (
[ 'recipe|r=s@' => "A recipe (without 'recipe[...]')" ],
[ 'default|d=s@' => "Default attribute (as KEY or KEY=VALUE)" ],
[ 'override=s@' => "Override attribute (as KEY or KEY=VALUE) (roles only)" ],
[ 'recipe|r=s@' => "A recipe (without 'recipe[...]')" ],
[ 'role|R=s@' => "A role (without 'role[...]')" ],
[ 'default|d=s@' => "Default attribute (as KEY or KEY=VALUE)" ],
[ 'override=s@' => "Override attribute (as KEY or KEY=VALUE) (roles only)" ],
);
}

Expand Down
7 changes: 5 additions & 2 deletions lib/Pantry/App/Command/apply.pm
Expand Up @@ -53,7 +53,7 @@ sub _apply_obj {

my $obj = $self->_check_name($type, $name);

$self->_apply_recipe($obj, $opt);
$self->_apply_runlist($obj, $opt);

for my $k ( sort keys %{$setters{$type}} ) {
if ( my $method = $setters{$type}{$k} ) {
Expand All @@ -76,11 +76,14 @@ sub _check_name {
return $obj;
}

sub _apply_recipe {
sub _apply_runlist {
my ($self, $obj, $opt) = @_;
if ($opt->{recipe}) {
$obj->append_to_run_list(map { "recipe[$_]" } @{$opt->{recipe}});
}
if ($opt->{role}) {
$obj->append_to_run_list(map { "role[$_]" } @{$opt->{role}});
}
return;
}

Expand Down
12 changes: 12 additions & 0 deletions t/app/apply.t
Expand Up @@ -34,6 +34,12 @@ my @cases = (
run_list => [ 'recipe[nginx]' ],
},
},
{
argv => [ qw/-R web/ ],
expected => {
run_list => [ 'role[web]' ],
},
},
{
argv => [ qw/-d nginx.port=80/ ],
expected => {
Expand Down Expand Up @@ -69,6 +75,12 @@ my @cases = (
run_list => [ 'recipe[nginx]' ],
},
},
{
argv => [ qw/-R web/ ],
expected => {
run_list => [ 'role[web]' ],
},
},
{
argv => [ qw/-d nginx.port=80/ ],
expected => {
Expand Down

0 comments on commit 6b5dc84

Please sign in to comment.