Skip to content

Commit a283bff

Browse files
committed
refactoring and moving...
1 parent d9dd1e4 commit a283bff

File tree

4 files changed

+191
-149
lines changed

4 files changed

+191
-149
lines changed

...

-110
This file was deleted.

...

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/...

bin/...

+79-38
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
#!/usr/bin/env perl
2-
# use XXX;use YAML;use YAML::Loader;
2+
use XXX;use YAML;use YAML::Loader;
33
# Next line removes site dirs, so we don't pull in non-core modules.
44
BEGIN { @INC = grep not(/\bsite/), @INC }
55

6+
# TODO:
7+
# - backup needs to save the .../conf file
8+
69
my $usage = <<'...';
710
8-
... - The Unix Dot File Manager
11+
... - The Unix Dot File Manager
912
1013
Usage: ... [options] command [command-options]
1114
1215
Commands:
13-
backup - Backup all the dot files that would be changed by 'install'.
14-
install - Copy or link all the dot files into your $HOME directory.
15-
-l | --links Use hardlinks (default)
16-
-s | --symlink Use symlinks
17-
-f | --copy Full copy
18-
list - List all the full paths of the files that would be installed.
19-
status - Get change status of all the dot repositories.
20-
conflicts - Show dot files that collide with ones from other repos
21-
update - Fetch changes from all the dot repositories.
22-
upgrade - Do update and then install.
23-
restore - Restore a backup.
24-
remove - DELETE all the dot files in $HOME that would be installed!!!
25-
configure path/to/dots-conf.yaml
26-
... can configure itself with this command and a conf file.
27-
env - Get input for a shell eval `... env`, useful for scripting.
16+
backup - Backup all the dot files that would be changed by 'install'.
17+
install - Copy or link all the dot files into your $HOME directory.
18+
-l | --links Use hardlinks (default)
19+
-s | --symlink Use symlinks
20+
-f | --copy Full copy
21+
list - List all the full paths of the files that would be installed.
22+
status - Get change status of all the dot repositories.
23+
conflicts - Show dot files that collide with ones from other repos.
24+
update - Fetch changes from all the dot repositories.
25+
upgrade - Do update and then install.
26+
restore - Restore a backup.
27+
remove - DELETE all the dot files in $HOME that would be installed!!!
28+
conf(igure) conf-file-path | conf-file-url | <stdin>
29+
- Put content into the .../conf configuration file.
30+
env - Get input for a shell eval `... env`, useful for scripting.
2831
2932
Options:
3033
-v --version Print the version and exit.
@@ -66,10 +69,20 @@ my $conf_file = "$root_dir/conf";
6669
my $config; # Config hash
6770
my $timestamp; # Time stamp
6871
my $restore_from; # Directory to restore from
69-
my $input_file;
72+
my $conf_path;
7073

7174
my $cli_install_method = '';
7275

76+
my $no_conf_msg = <<"...";
77+
Error: '$conf_file' does not exist.
78+
79+
Run `... conf <path-or-url>` to set it up.
80+
81+
You can also copy $root_dir/conf.example to $conf_file
82+
and edit appropriately.
83+
84+
...
85+
7386
TOP: {
7487
my $class = __PACKAGE__;
7588
$class->parse_command_line();
@@ -80,7 +93,7 @@ TOP: {
8093
sub parse_command_line {
8194
my $class = shift;
8295
if (@ARGV == 0) {
83-
$command = 'help';
96+
$command = 'default';
8497
}
8598
elsif ($ARGV[0] =~ /^(-\?|-h|--help)$/) {
8699
$command = 'help';
@@ -99,8 +112,7 @@ sub parse_command_line {
99112
}
100113
elsif ($ARGV[0] =~ /^conf(igure)?$/) {
101114
$command = 'configure';
102-
$input_file = splice(@ARGV, 1, 1)
103-
or die "configure requires a dots-conf.yaml file";
115+
$conf_path = splice(@ARGV, 1, 1) || '';
104116
}
105117
elsif ($ARGV[0] =~ /^-/) {
106118
die "Error: '$ARGV[0]' is an invalid option\n";
@@ -138,25 +150,24 @@ sub setup {
138150
my $class = shift;
139151

140152
-d $root_dir or die "Error: $root_dir is not a directory\n";
141-
-f $conf_file or die <<"...";
142-
Error: $conf_file does not exist.
143-
144-
You should copy $root_dir/conf.example to $conf_file
145-
and edit appropriately.
146-
147-
...
153+
-f $conf_file or die $no_conf_msg;
148154
$config = YAML::Tiny::LoadFile($conf_file);
149155

150156
$config->{dot_paths_base} ||= 'src';
151157

152-
die "Error: 'dot_paths' not defined in $conf_file\n"
153-
unless defined $config->{dot_paths};
154-
die "Error: 'dot_paths' needs to be a sequence of mappings.\n"
155-
if ref($config->{dot_paths}) ne 'ARRAY' or
156-
not(@{$config->{dot_paths}}) or
157-
grep {ref ne 'HASH'} @{$config->{dot_paths}};
158-
die "Error: each dot_path entry must have a 'path' value\n"
159-
if grep {not defined $_->{path}} @{$config->{dot_paths}};
158+
my $dots = $config->{dots} || $config->{dot_paths}
159+
or die "Error: 'dots' not defined in $conf_file\n";
160+
die "Error: 'dots' needs to be a sequence of mappings.\n"
161+
if ref($dots) ne 'ARRAY' or
162+
not(@$dots) or
163+
grep {ref ne 'HASH'} @$dots;
164+
die "Error: each dot_path entry must have a 'path' or 'repo' value\n"
165+
if grep {
166+
not defined $_->{path} and
167+
not defined $_->{repo}
168+
} @$dots;
169+
delete $config->{dot_paths};
170+
$config->{dots} = $dots;
160171

161172
$config->{auto_backup} =
162173
not(exists($config->{auto_backup})) ? 1 :
@@ -174,6 +185,11 @@ and edit appropriately.
174185
$timestamp = sprintf "%04d%02d%02d-%02d%02d%02d", $year, $mon, $day, $hour, $min, $sec;
175186
}
176187

188+
sub handle_default {
189+
my $class = shift;
190+
$class->handle_help;
191+
}
192+
177193
sub handle_help {
178194
my $class = shift;
179195
print $usage;
@@ -195,7 +211,31 @@ EOT
195211

196212
sub handle_configure {
197213
my $class = shift;
198-
$config = YAML::Tiny::LoadFile($input_file);
214+
die "'$conf_file' already exists\n"
215+
if -f $conf_file;
216+
if (not $conf_path) {
217+
my $text = do {local $/; <STDIN>};
218+
open OUT, ">$conf_file" or die "Can't open $conf_file for output";
219+
print OUT $text;
220+
close $text;
221+
}
222+
elsif ($conf_path =~ m!^https?://!) {
223+
$class->_run_sys("curl $conf_path > $conf_file");
224+
}
225+
elsif ($conf_path =~ /:/) {
226+
$class->_run_sys("scp $conf_path $conf_file");
227+
}
228+
elsif (-f $conf_path) {
229+
$class->_run_sys("cp $conf_path $conf_file");
230+
}
231+
else {
232+
die "Unknown argument '$conf_path' for '... configure'\n";
233+
}
234+
}
235+
236+
sub handle_configure_xxx {
237+
my $class = shift;
238+
$config = YAML::Tiny::LoadFile($conf_path);
199239
my $array = $class->_determine_config_section($config)
200240
or die "Can't determine a config for this environment\n";
201241
my @paths;
@@ -230,7 +270,7 @@ Created $conf_file
230270
231271
Now run this command to install your dot files:
232272
233-
~/.../bin/... install
273+
~/.../... install
234274
...
235275
}
236276

@@ -284,6 +324,7 @@ sub _each_make {
284324

285325
sub handle_install {
286326
my $class = shift;
327+
$class->check_all_paths();
287328
$class->handle_backup('quiet') if $config->{auto_backup};
288329
$class->handle_dots_install();
289330
$class->handle_dots_deps();

conf.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# a 'path' of the directory, which if relative, is relative to the
1414
# value of 'dot_paths_base', above.
1515
#
16-
dot_paths:
16+
dots:
1717
- path: dotdotdot
1818
- path: personal
1919
- path: private

0 commit comments

Comments
 (0)