| 1 |
package App::Yath::Options::Workspace; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
our $VERSION = '1.000179'; |
| 6 |
|
| 7 |
use File::Spec(); |
| 8 |
use File::Path qw/remove_tree/; |
| 9 |
use File::Temp qw/tempdir/; |
| 10 |
|
| 11 |
use Test2::Harness::Util qw/clean_path chmod_tmp/; |
| 12 |
|
| 13 |
use App::Yath::Options; |
| 14 |
|
| 15 |
option_group {prefix => 'workspace', category => "Workspace Options"} => sub { |
| 16 |
option tmp_dir => ( |
| 17 |
type => 's', |
| 18 |
short => 't', |
| 19 |
alt => ['tmpdir'], |
| 20 |
description => 'Use a specific temp directory (Default: use system temp dir)', |
| 21 |
env_vars => [qw/T2_HARNESS_TEMP_DIR YATH_TEMP_DIR TMPDIR TEMPDIR TMP_DIR TEMP_DIR/], |
| 22 |
default => sub { File::Spec->tmpdir }, |
| 23 |
); |
| 24 |
|
| 25 |
option workdir => ( |
| 26 |
type => 's', |
| 27 |
short => 'w', |
| 28 |
description => 'Set the work directory (Default: new temp directory)', |
| 29 |
env_vars => [qw/T2_WORKDIR YATH_WORKDIR/], |
| 30 |
clear_env_vars => 1, |
| 31 |
normalize => \&clean_path, |
| 32 |
); |
| 33 |
|
| 34 |
option clear => ( |
| 35 |
short => 'C', |
| 36 |
description => 'Clear the work directory if it is not already empty', |
| 37 |
); |
| 38 |
|
| 39 |
post sub { |
| 40 |
my %params = @_; |
| 41 |
my $settings = $params{settings}; |
| 42 |
|
| 43 |
if (my $workdir = $settings->workspace->workdir) { |
| 44 |
if (-d $workdir) { |
| 45 |
remove_tree($workdir, {safe => 1, keep_root => 1}) if $settings->workspace->clear; |
| 46 |
} |
| 47 |
else { |
| 48 |
mkdir($workdir) or die "Could not create workdir: $!"; |
| 49 |
chmod_tmp($workdir); |
| 50 |
} |
| 51 |
|
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
my $project = $settings->harness->project; |
| 56 |
my $template = join '-' => ( "yath", $$, "XXXXXX"); |
| 57 |
|
| 58 |
my $tmpdir = tempdir( |
| 59 |
$template, |
| 60 |
DIR => $settings->workspace->tmp_dir, |
| 61 |
CLEANUP => !($settings->debug->keep_dirs || $params{command}->always_keep_dir), |
| 62 |
); |
| 63 |
chmod_tmp($tmpdir); |
| 64 |
|
| 65 |
$settings->workspace->field(workdir => $tmpdir); |
| 66 |
}; |
| 67 |
}; |
| 68 |
|
| 69 |
1; |
| 70 |
|
| 71 |
=pod |
| 72 |
|
| 73 |
=encoding UTF-8 |
| 74 |
|
| 75 |
=head1 NAME |
| 76 |
|
| 77 |
App::Yath::Options::Workspace - Options for specifying the yath work dir. |
| 78 |
|
| 79 |
=head1 DESCRIPTION |
| 80 |
|
| 81 |
Options regarding the yath working directory. |
| 82 |
|
| 83 |
=head1 PROVIDED OPTIONS |
| 84 |
|
| 85 |
=head2 COMMAND OPTIONS |
| 86 |
|
| 87 |
=head3 Workspace Options |
| 88 |
|
| 89 |
=over 4 |
| 90 |
|
| 91 |
=item --clear |
| 92 |
|
| 93 |
=item -C |
| 94 |
|
| 95 |
=item --no-clear |
| 96 |
|
| 97 |
Clear the work directory if it is not already empty |
| 98 |
|
| 99 |
|
| 100 |
=item --tmp-dir ARG |
| 101 |
|
| 102 |
=item --tmp-dir=ARG |
| 103 |
|
| 104 |
=item --tmpdir ARG |
| 105 |
|
| 106 |
=item --tmpdir=ARG |
| 107 |
|
| 108 |
=item -t ARG |
| 109 |
|
| 110 |
=item -t=ARG |
| 111 |
|
| 112 |
=item --no-tmp-dir |
| 113 |
|
| 114 |
Use a specific temp directory (Default: use system temp dir) |
| 115 |
|
| 116 |
Can also be set with the following environment variables: C<T2_HARNESS_TEMP_DIR>, C<YATH_TEMP_DIR>, C<TMPDIR>, C<TEMPDIR>, C<TMP_DIR>, C<TEMP_DIR> |
| 117 |
|
| 118 |
|
| 119 |
=item --workdir ARG |
| 120 |
|
| 121 |
=item --workdir=ARG |
| 122 |
|
| 123 |
=item -w ARG |
| 124 |
|
| 125 |
=item -w=ARG |
| 126 |
|
| 127 |
=item --no-workdir |
| 128 |
|
| 129 |
Set the work directory (Default: new temp directory) |
| 130 |
|
| 131 |
Can also be set with the following environment variables: C<T2_WORKDIR>, C<YATH_WORKDIR> |
| 132 |
|
| 133 |
|
| 134 |
=back |
| 135 |
|
| 136 |
=head1 SOURCE |
| 137 |
|
| 138 |
The source code repository for Test2-Harness can be found at |
| 139 |
F<http://github.com/Test-More/Test2-Harness/>. |
| 140 |
|
| 141 |
=head1 MAINTAINERS |
| 142 |
|
| 143 |
=over 4 |
| 144 |
|
| 145 |
=item Chad Granum E<lt>[email protected]<gt> |
| 146 |
|
| 147 |
=back |
| 148 |
|
| 149 |
=head1 AUTHORS |
| 150 |
|
| 151 |
=over 4 |
| 152 |
|
| 153 |
=item Chad Granum E<lt>[email protected]<gt> |
| 154 |
|
| 155 |
=back |
| 156 |
|
| 157 |
=head1 COPYRIGHT |
| 158 |
|
| 159 |
Copyright 2020 Chad Granum E<lt>[email protected]<gt>. |
| 160 |
|
| 161 |
This program is free software; you can redistribute it and/or |
| 162 |
modify it under the same terms as Perl itself. |
| 163 |
|
| 164 |
See F<http://dev.perl.org/licenses/> |
| 165 |
|
| 166 |
=cut |