-
Notifications
You must be signed in to change notification settings - Fork 213
/
ScriptConfigCommand.pm
230 lines (163 loc) · 5.59 KB
/
ScriptConfigCommand.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package App::Sqitch::Role::ScriptConfigCommand;
use 5.010;
use strict;
use warnings;
use utf8;
use Moo::Role;
use App::Sqitch::Types qw(Maybe Dir Str);
use Path::Class;
use namespace::autoclean;
requires 'options';
requires 'configure';
has reworked_dir => (
is => 'ro',
isa => Maybe[Dir],
);
has extension => (
is => 'ro',
isa => Maybe[Str],
);
for my $script (qw(deploy revert verify)) {
has "$script\_dir" => (
is => 'ro',
isa => Maybe[Dir],
);
has "reworked_$script\_dir" => (
is => 'ro',
isa => Maybe[Dir],
lazy => 1,
default => sub {
my $dir = shift->reworked_dir or return undef;
$dir->subdir($script);
},
);
}
around options => sub {
my ($orig, $class) = @_;
return ($class->$orig), qw(
deploy-dir=s
revert-dir=s
verify-dir=s
reworked-dir=s
reworked-deploy-dir=s
reworked-revert-dir=s
reworked-verify-dir=s
extension=s
);
};
around configure => sub {
my ( $orig, $class, $config, $opt ) = @_;
for my $dir (
'reworked_dir',
map { ("$_\_dir", "reworked_$_\_dir") } qw(deploy revert verify)
) {
if ( my $str = $opt->{$dir} ) {
$opt->{$dir} = dir $str;
}
}
return $class->$orig($config, $opt);
};
sub script_config {
my $self = shift;
my $config = {};
for my $attr (
'reworked_dir',
(map { ("$_\_dir", "reworked_$_\_dir") } qw(deploy revert verify)),
'extension'
) {
if (my $val = $self->$attr) {
$config->{$attr} = $val;
}
}
return $config;
}
sub directories_for {
my ($self, $target) = @_;
return (
$self->deploy_dir || $target->deploy_dir,
$self->revert_dir || $target->revert_dir,
$self->verify_dir || $target->verify_dir,
$self->reworked_deploy_dir || $target->reworked_deploy_dir,
$self->reworked_revert_dir || $target->reworked_revert_dir,
$self->reworked_verify_dir || $target->reworked_verify_dir,
);
}
1;
__END__
=head1 Name
App::Sqitch::Role::ScriptConfigCommand - A command that reverts and deploys
=head1 Synopsis
package App::Sqitch::Command::init;
extends 'App::Sqitch::Command';
with 'App::Sqitch::Role::ScriptConfigCommand';
=head1 Description
This role encapsulates the common attributes and methods required by commands
that deal with change script configuration, including script directories and
extensions.
=head1 Interface
=head2 Class Methods
=head3 C<options>
my @opts = App::Sqitch::Command::checkout->options;
Adds options common to the commands that manage script configuration.
=head3 C<configure>
Configures the options common to commands manage script configuration.
=head2 Attributes
=head3 C<deploy_dir>
Path to the directory containing deploy scripts.
=head3 C<revert_dir>
Path to the directory containing revert scripts.
=head3 C<verify_dir>
Path to the directory containing verify scripts.
=head3 C<reworked_dir>
Path to the directory containing subdirectories for reworked change scripts.
=head3 C<reworked_deploy_dir>
Path to the directory containing reworked deploy scripts.
=head3 C<reworked_revert_dir>
Path to the directory containing reworked revert scripts.
=head3 C<reworked_verify_dir>
Path to the directory containing reworked verify scripts.
=head3 C<extension>
The file extension to use for change script files.
=head2 Instance Methods
=head3 C<script_config>
my $config = $cmd->script_config;
Returns a hash reference of script configuration values. They keys are
suitable for use in L<App::Sqitch::Config> sections, while the keys are the
values. All but the C<extension> key are L<Path::Class::Dir> objects.
=head3 C<directories_for>
my @dirs = $cmd->directories_for($target);
Returns a list of script directories for the target. Options passed to the
command are preferred. Paths are pulled from the command only when they have
not been passed as options.
=head1 See Also
=over
=item L<App::Sqitch::Command::init>
The C<init> command initializes a Sqitch project, setting up the change script
configuration and directories.
=item L<App::Sqitch::Command::engine>
The C<engine> command manages engine configuration, including engine-specific
change script configuration.
=item L<App::Sqitch::Command::target>
The C<engine> command manages target configuration, including target-specific
change script configuration.
=back
=head1 Author
David E. Wheeler <david@justatheory.com>
=head1 License
Copyright (c) 2012-2015 iovation Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=cut