dotrepo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dotrepo.rb +1 -0
- data/lib/dotrepo/cli.rb +36 -16
- data/lib/dotrepo/config_file.rb +2 -2
- data/lib/dotrepo/dot_file.rb +19 -0
- data/lib/dotrepo/version.rb +1 -1
- data/spec/lib/dotrepo/config_file_spec.rb +2 -2
- data/spec/lib/dotrepo/dot_file_spec.rb +65 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5ba5062edfa0ebf17fa549c08d6b2506b91e4cd
|
4
|
+
data.tar.gz: aa90328f26a414509a366b77d8a8f7877adbc2b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd26bbf6d221fe89f4558d88d68d13f7013cb5b929ae403e1e1072e340ea05ba6e9195aea209326cd5e56e861c53fa37a755611aeac047085b7d6be35ab1e163
|
7
|
+
data.tar.gz: ba7f4fe45bee269fe8036061ffb99a3ef107cc0b232a4840a6cfe0285a8952d86d83d781cacb6f17a1c31a81bb02dc47ac90a6e567a15fffb435299f66c7ebeb
|
data/lib/dotrepo.rb
CHANGED
data/lib/dotrepo/cli.rb
CHANGED
@@ -17,37 +17,57 @@ module Dotrepo
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
desc "setup", "setup your
|
20
|
+
desc "setup", "setup your dotfile repo"
|
21
21
|
method_option :repo,
|
22
22
|
aliases: "-r",
|
23
23
|
desc: "repo to pull dotfiles from"
|
24
|
+
method_option :"no-repo",
|
25
|
+
type: :boolean,
|
26
|
+
default: false,
|
27
|
+
desc: "setup without pulling a repo"
|
28
|
+
method_option :files,
|
29
|
+
aliases: "-f",
|
30
|
+
type: :array,
|
31
|
+
desc: "list of files to copy & symlink"
|
24
32
|
def setup
|
25
|
-
|
26
|
-
|
27
|
-
|
33
|
+
if options[:repo]
|
34
|
+
system "git clone #{options[:repo]} #{config.source}"
|
35
|
+
else
|
36
|
+
unless options[:"no-repo"]
|
37
|
+
shell.say_status "error", "you must specify a repo", :red
|
38
|
+
return
|
39
|
+
end
|
28
40
|
end
|
29
41
|
|
30
|
-
|
31
|
-
|
42
|
+
manager = DotFileManager.new( config.source, config.destination )
|
43
|
+
manager.symlink_dotfiles
|
44
|
+
|
45
|
+
if options[:files]
|
46
|
+
options[:files].each do |file_path|
|
47
|
+
file = DotFile.new( file_path, manager )
|
48
|
+
unless file.linked?
|
49
|
+
file.create_linked_file!
|
50
|
+
else
|
51
|
+
shell.say_status "info", "#{file_path} already linked", :bold
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
32
55
|
end
|
33
56
|
|
34
|
-
desc "refresh", "
|
57
|
+
desc "refresh", "link new dotfiles"
|
35
58
|
def refresh
|
36
59
|
# runs the manager again to symlink new files & prune abandoned files
|
37
60
|
DotFileManager.new( config.source, config.destination ).symlink_dotfiles
|
38
61
|
end
|
39
62
|
|
40
|
-
|
41
|
-
def
|
63
|
+
desc "repo", "cd to the repo directory"
|
64
|
+
def repo
|
65
|
+
puts File.expand_path(config.source)
|
42
66
|
end
|
43
67
|
|
44
|
-
desc "
|
45
|
-
def
|
46
|
-
|
47
|
-
# - does the source exist as a git repo
|
48
|
-
# - is the source up to date & free of modified files
|
49
|
-
# - does the source have any dotfiles
|
50
|
-
# - does the destination exist
|
68
|
+
desc "uninstall", "revert symlinked files to plain dotfiles"
|
69
|
+
def uninstall
|
70
|
+
say "method not implemented yet"
|
51
71
|
end
|
52
72
|
|
53
73
|
private
|
data/lib/dotrepo/config_file.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Dotrepo
|
2
2
|
class ConfigFile
|
3
|
-
FILE_PATH = File.join( File.expand_path("~"), ".
|
3
|
+
FILE_PATH = File.join( File.expand_path("~"), ".dotrepo/config" )
|
4
4
|
|
5
5
|
attr_reader :data
|
6
6
|
|
@@ -28,7 +28,7 @@ module Dotrepo
|
|
28
28
|
|
29
29
|
def defaults
|
30
30
|
{
|
31
|
-
"source" => '~/.
|
31
|
+
"source" => '~/.dotrepo/repo',
|
32
32
|
"destination" => '~/'
|
33
33
|
}
|
34
34
|
end
|
data/lib/dotrepo/dot_file.rb
CHANGED
@@ -26,6 +26,25 @@ module Dotrepo
|
|
26
26
|
File.readlink(destination) == source
|
27
27
|
end
|
28
28
|
|
29
|
+
def create_linked_file!
|
30
|
+
if source_exists?
|
31
|
+
raise "Source file already exists for #{File.basename(source)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
FileUtils.mkdir_p File.dirname(source)
|
35
|
+
|
36
|
+
if destination_exists?
|
37
|
+
FileUtils.cp destination, source
|
38
|
+
backup_destination
|
39
|
+
else
|
40
|
+
File.open( source, 'wb' ) do |file|
|
41
|
+
file.write ""
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
symlink_to_destination!
|
46
|
+
end
|
47
|
+
|
29
48
|
def symlink_to_destination
|
30
49
|
return if linked?
|
31
50
|
|
data/lib/dotrepo/version.rb
CHANGED
@@ -24,14 +24,14 @@ describe Dotrepo::ConfigFile do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "uses default data w/ no config file" do
|
27
|
-
expect( described_class.new.data ).to eq({ "source" => "~/.
|
27
|
+
expect( described_class.new.data ).to eq({ "source" => "~/.dotrepo/repo",
|
28
28
|
"destination" => "~/" })
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#source" do
|
33
33
|
it "returns the 'source' from #data" do
|
34
|
-
expect( described_class.new.source ).to eq "~/.
|
34
|
+
expect( described_class.new.source ).to eq "~/.dotrepo/repo"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -141,6 +141,71 @@ describe Dotrepo::DotFile do
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
+
describe "#create_linked_file!" do
|
145
|
+
let(:source_dir) { File.join( Given::TMP, "source" ) }
|
146
|
+
let(:destination_dir) { File.join( Given::TMP, "destination" ) }
|
147
|
+
let(:manager_double) {
|
148
|
+
double("Manager",
|
149
|
+
source: source_dir,
|
150
|
+
destination: destination_dir )
|
151
|
+
}
|
152
|
+
let(:subject) { Dotrepo::DotFile.new("/foo/bar", manager_double) }
|
153
|
+
|
154
|
+
before :each do
|
155
|
+
FileUtils.mkdir_p( File.dirname(subject.destination) )
|
156
|
+
end
|
157
|
+
|
158
|
+
after :each do
|
159
|
+
Given.cleanup!
|
160
|
+
end
|
161
|
+
|
162
|
+
context "source file exists" do
|
163
|
+
it "raises error" do
|
164
|
+
allow( File ).to receive(:exist?)
|
165
|
+
.with("/source/foo/bar")
|
166
|
+
.and_return(true)
|
167
|
+
|
168
|
+
expect{
|
169
|
+
subject.create_linked_file!
|
170
|
+
}.to raise_error
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "destination file doesn't exist" do
|
175
|
+
it "creates a blank source file" do
|
176
|
+
subject.create_linked_file!
|
177
|
+
expect( File.exist?( subject.source ) ).to be_truthy
|
178
|
+
end
|
179
|
+
it "symlinks newly created source file" do
|
180
|
+
subject.create_linked_file!
|
181
|
+
expect( subject ).to be_linked
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "destination file exists" do
|
186
|
+
before :each do
|
187
|
+
Given.file File.join("destination", subject.path)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "copies the destination to source" do
|
191
|
+
expect( FileUtils ).to receive(:cp)
|
192
|
+
.with( File.join(destination_dir, subject.path), File.join(source_dir, subject.path) )
|
193
|
+
.and_call_original
|
194
|
+
|
195
|
+
subject.create_linked_file!
|
196
|
+
end
|
197
|
+
it "backs up the destination file" do
|
198
|
+
expect( subject ).to receive(:backup_destination)
|
199
|
+
.and_call_original
|
200
|
+
subject.create_linked_file!
|
201
|
+
end
|
202
|
+
it "symlinks the source file to destination" do
|
203
|
+
expect( subject ).to receive(:symlink_to_destination!)
|
204
|
+
subject.create_linked_file!
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
144
209
|
describe "#symlink_to_destination!" do
|
145
210
|
|
146
211
|
let(:manager_double) {
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotrepo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Sloan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: ' A simple manager for your dotfiles '
|