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 { sub data_options {
return ( return (
[ 'recipe|r=s@' => "A recipe (without 'recipe[...]')" ], [ 'recipe|r=s@' => "A recipe (without 'recipe[...]')" ],
[ 'default|d=s@' => "Default attribute (as KEY or KEY=VALUE)" ], [ 'role|R=s@' => "A role (without 'role[...]')" ],
[ 'override=s@' => "Override attribute (as KEY or KEY=VALUE) (roles only)" ], [ '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); my $obj = $self->_check_name($type, $name);


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


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


sub _apply_recipe { sub _apply_runlist {
my ($self, $obj, $opt) = @_; my ($self, $obj, $opt) = @_;
if ($opt->{recipe}) { if ($opt->{recipe}) {
$obj->append_to_run_list(map { "recipe[$_]" } @{$opt->{recipe}}); $obj->append_to_run_list(map { "recipe[$_]" } @{$opt->{recipe}});
} }
if ($opt->{role}) {
$obj->append_to_run_list(map { "role[$_]" } @{$opt->{role}});
}
return; 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]' ], run_list => [ 'recipe[nginx]' ],
}, },
}, },
{
argv => [ qw/-R web/ ],
expected => {
run_list => [ 'role[web]' ],
},
},
{ {
argv => [ qw/-d nginx.port=80/ ], argv => [ qw/-d nginx.port=80/ ],
expected => { expected => {
Expand Down Expand Up @@ -69,6 +75,12 @@ my @cases = (
run_list => [ 'recipe[nginx]' ], run_list => [ 'recipe[nginx]' ],
}, },
}, },
{
argv => [ qw/-R web/ ],
expected => {
run_list => [ 'role[web]' ],
},
},
{ {
argv => [ qw/-d nginx.port=80/ ], argv => [ qw/-d nginx.port=80/ ],
expected => { expected => {
Expand Down

0 comments on commit 6b5dc84

Please sign in to comment.