line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::VTide::Command::Save; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2016-01-30 20:38:50 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1527
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
2509
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
11
|
1
|
|
|
1
|
|
5
|
use version; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
12
|
1
|
|
|
1
|
|
61
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
51
|
|
13
|
1
|
|
|
1
|
|
65
|
use List::MoreUtils qw/uniq/; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
12
|
|
14
|
1
|
|
|
1
|
|
793
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
15
|
1
|
|
|
1
|
|
355
|
use YAML::Syck; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
16
|
1
|
|
|
1
|
|
10
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
815
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
extends 'App::VTide::Command::Run'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = version->new('1.0.4'); |
21
|
|
|
|
|
|
|
our $NAME = 'save'; |
22
|
|
|
|
|
|
|
our $OPTIONS = [ |
23
|
|
|
|
|
|
|
'name|n=s', |
24
|
|
|
|
|
|
|
'record_env|record-env|r', |
25
|
|
|
|
|
|
|
'diff_env|diff-env|d', |
26
|
|
|
|
|
|
|
'save_env|save-env|s', |
27
|
|
|
|
|
|
|
'test|T!', |
28
|
|
|
|
|
|
|
'verbose|v+', |
29
|
|
|
|
|
|
|
]; |
30
|
0
|
|
|
0
|
1
|
|
sub details_sub { return ( $NAME, $OPTIONS )}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has env_store => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
default => '.vtide/.current-env', |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub run { |
38
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ( $self->defaults->{record_env} ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->record_env(); |
42
|
0
|
|
|
|
|
|
$self->hooks->run('save_record_env'); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ( $self->defaults->{diff_env} ) { |
45
|
0
|
|
|
|
|
|
$self->defaults->{verbose} = 1; |
46
|
0
|
|
|
|
|
|
$self->diff_env(); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ( $self->defaults->{save_env} ) { |
49
|
0
|
|
|
|
|
|
$self->save_env( $self->diff_env() ); |
50
|
0
|
|
|
|
|
|
$self->hooks->run( 'save_save_env', $self->diff_env() ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
|
|
|
|
|
|
# default name is the project name |
54
|
0
|
|
|
|
|
|
$self->save( $self->defaults->{name}, @ARGV ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub save { |
61
|
0
|
|
|
0
|
1
|
|
my ($self, $name, @files) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
0
|
|
|
|
my $file = $ENV{VTIDE_CONFIG} || '.vtide.yml'; |
64
|
0
|
|
|
|
|
|
my $config = LoadFile($file); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$config->{editor}{files}{$name} = [ @files ]; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
DumpFile($file, $config); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub record_env { |
74
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
path($self->env_store)->parent->mkpath; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
DumpFile($self->env_store, \%ENV); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub diff_env { |
84
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $old_env = LoadFile($self->env_store); |
87
|
0
|
|
|
|
|
|
my @keys = uniq sort keys %ENV, keys %$old_env; |
88
|
0
|
|
|
|
|
|
my %diff; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
for my $key (@keys) { |
91
|
0
|
0
|
0
|
|
|
|
next if ($ENV{$key} || '') eq ($old_env->{$key} || ''); |
|
|
|
0
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if ( $self->defaults->{verbose} ) { |
93
|
0
|
|
0
|
|
|
|
printf "%-15s %-45.45s %-45.45s\n", $key, $ENV{$key} || q{''}, $old_env->{$key} || q{''}; |
|
|
|
0
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
$diff{$key} = $ENV{$key}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return %diff; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub save_env { |
102
|
0
|
|
|
0
|
1
|
|
my ($self, %env) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
0
|
|
|
|
my $file = $ENV{VTIDE_CONFIG} || '.vtide.yml'; |
105
|
0
|
|
|
|
|
|
my $config = LoadFile($file); |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ( $self->defaults->{terminal} ) { |
108
|
0
|
|
|
|
|
|
my $term = $self->defaults->{terminal}; |
109
|
|
|
|
|
|
|
$config->{terminals}{$term}{env} = { |
110
|
0
|
0
|
|
|
|
|
%{ $config->{terminals}{$term}{env} || {} }, |
|
0
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
%env, |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
else { |
115
|
|
|
|
|
|
|
$config->{default}{env} = { |
116
|
0
|
0
|
|
|
|
|
%{ $config->{default}{env} || {} }, |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
%env, |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
DumpFile($file, $config); |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
App::VTide::Command::Save - Save configuration changes |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 VERSION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This documentation refers to App::VTide::Command::Save version 1.0.4 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SYNOPSIS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
vtide save [(--name|-n) files-name] file-or-glob (file-or-glob...) |
141
|
|
|
|
|
|
|
vtide save --record-env |
142
|
|
|
|
|
|
|
vtide save --diff-env |
143
|
|
|
|
|
|
|
vtide save --save-env |
144
|
|
|
|
|
|
|
vtide save [--help|--man] |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
OPTIONS: |
147
|
|
|
|
|
|
|
-n --name[=]str Save the listed files or globs to the editor files list |
148
|
|
|
|
|
|
|
under this name (Default is the project name) |
149
|
|
|
|
|
|
|
-r --record-env Record the current environment (use before running commands |
150
|
|
|
|
|
|
|
like nvm, rvm and perlbrew) |
151
|
|
|
|
|
|
|
-d --diff-env Show the diff of the current environment and recorded |
152
|
|
|
|
|
|
|
environment |
153
|
|
|
|
|
|
|
-s --save-env Save the environment differences to .vtide.yml |
154
|
|
|
|
|
|
|
-v --verbose Show more verbose output. |
155
|
|
|
|
|
|
|
--help Show this help |
156
|
|
|
|
|
|
|
--man Show full documentation |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 DESCRIPTION |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This L<App::VTide> command saves extra information to the C<.vtide.yml> config |
161
|
|
|
|
|
|
|
file. There are two forms: |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=over 4 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item files |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Saving files or globs to the editor/files list makes it easier to add new |
168
|
|
|
|
|
|
|
groups of files. The name of the groups is specified by the C<--name> |
169
|
|
|
|
|
|
|
parameter. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item environment |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Saving environment variable changes so specific groups of environment variables |
174
|
|
|
|
|
|
|
can be set up each time a session is started. This is a multi step process |
175
|
|
|
|
|
|
|
where the current environment before changes are saved via C<--record=env> then |
176
|
|
|
|
|
|
|
the changes are made (e.g. running L<perlbrew>, C<nvm>, C<rvm> etc) and those |
177
|
|
|
|
|
|
|
changes can be viewed via C<--dif-env> and recorded to the C<.vtide.yml> file |
178
|
|
|
|
|
|
|
via C<--save-env>. This creates a temporary file C<.current-env> to store the |
179
|
|
|
|
|
|
|
environment variables when C<--record-env> is run. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 C<run ()> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Need to implement |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 C<save ($name, @files)> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Saves new file group C<$name> with the file or glob patters from C<@files> |
192
|
|
|
|
|
|
|
into the local C<.vtide.yml> config file. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 C<record_env ()> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Save the current environment variables to a temporary file |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 C<diff_env ()> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Find the environment keys that differ in the current environment vs that stored |
201
|
|
|
|
|
|
|
in the temporary file |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 C<save_env ()> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Save environment differences to the projects C<.vtide.yml> file |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 C<details_sub ()> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Returns the commands details. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 C<env_store> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
The name of the temporary file for storing the environment variables |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 HOOKS |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 C<save_record_env ()> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 C<save_save_env ( $diff_env )> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
There are no known bugs in this module. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Patches are welcome. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 AUTHOR |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Copyright (c) 2016 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
246
|
|
|
|
|
|
|
All rights reserved. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
249
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
250
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
251
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
252
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=cut |