dotrepo 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3731baa7ddeb1d596e711460693b68a99861b8f0
4
- data.tar.gz: 220caf4af84fbbd39993a8374e3c77f8fcb71fd9
3
+ metadata.gz: f5ba5062edfa0ebf17fa549c08d6b2506b91e4cd
4
+ data.tar.gz: aa90328f26a414509a366b77d8a8f7877adbc2b4
5
5
  SHA512:
6
- metadata.gz: 245a836d8fefc3ec02827f67375d5ceff5f44387f2fc2dde11af556405a8b74a376445d7fb61a91417ffccdddfc0fe6def3537664d9a5237b2519052be0b2937
7
- data.tar.gz: fe26393479992bb2016698801968dcb10791e4a9689aaf08415b7b29871558c37d1649ccad85b8e7725a0b1a76b4020c100feaeaf56bed5b65710770ee6abd92
6
+ metadata.gz: cd26bbf6d221fe89f4558d88d68d13f7013cb5b929ae403e1e1072e340ea05ba6e9195aea209326cd5e56e861c53fa37a755611aeac047085b7d6be35ab1e163
7
+ data.tar.gz: ba7f4fe45bee269fe8036061ffb99a3ef107cc0b232a4840a6cfe0285a8952d86d83d781cacb6f17a1c31a81bb02dc47ac90a6e567a15fffb435299f66c7ebeb
data/lib/dotrepo.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'fileutils'
2
3
 
3
4
  require_relative 'dotrepo/dot_file'
4
5
  require_relative 'dotrepo/dot_file_manager'
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 dotbox"
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
- unless options[:repo]
26
- shell.say_status "error", "you must specify a repo", :red
27
- return
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
- system "git clone #{options[:repo]} #{config.source}"
31
- DotFileManager.new( config.source, config.destination ).symlink_dotfiles
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", "update linked dotfiles"
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
- dec "uninstall", "revert symlinked files to plain dotfiles"
41
- def uninstall
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 "doctor", "analyze your setup for common issues"
45
- def doctor
46
- # do some smart checking based on info
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
@@ -1,6 +1,6 @@
1
1
  module Dotrepo
2
2
  class ConfigFile
3
- FILE_PATH = File.join( File.expand_path("~"), ".dotbox/config" )
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" => '~/.dotbox/box',
31
+ "source" => '~/.dotrepo/repo',
32
32
  "destination" => '~/'
33
33
  }
34
34
  end
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Dotrepo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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" => "~/.dotbox/box",
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 "~/.dotbox/box"
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.1
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-12 00:00:00.000000000 Z
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 '