lookfile 0.1.2 → 0.1.3

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: aaf6dabdfc5e632a80a8ffb6a0e6d4b75b6653d4
4
- data.tar.gz: 932108b2dca284607f1ca8f5d15a8f9f018f9f64
3
+ metadata.gz: 7bb133639dd73f281038157b744388e3b3b00435
4
+ data.tar.gz: d203dcc60e0391acc09ff7c50c3dc9d275d1f7bb
5
5
  SHA512:
6
- metadata.gz: 9f446a1d71a35405d5b6b6eb917454891cf6cc694fbb5173855afbc372ff91f79bff5f601d1349d7215059bab079cfb38ec938208430bd304180e22e33d001af
7
- data.tar.gz: ee7293dfb6f86c44de310207eb307e4975582641c61bf3c528f161ac92b0e3888fc45e9dca65ea5f128e20f8d7078215a4a34a2330ebb98a26af6c8232631b16
6
+ metadata.gz: 03632a0c55a6a4af86f9957bd9b375e123c7320b3403bf66b1054ea6bc774c5b0b5f4cec11d37afaecda7c49328ac0af15f864702ecf419cd778b5b9dbac39ec
7
+ data.tar.gz: 8ae3f51c2b2a032ed0214e90d566dca3bd30ffe87bc4eda99c0965e9925f6f86c0d6f0a4aea71abd2b4f2027ed596d75db757e784630396a63f41da941ce1dcf
data/README.md CHANGED
@@ -34,8 +34,14 @@ Or install it yourself as:
34
34
  add $ lookfile add [file 0] [file 1] ... [file n]
35
35
  - Add files to lookfile
36
36
 
37
- update $ lookfile update
38
- - Update files to lookfile and push to repository
37
+ push $ lookfile push
38
+ - Commit files on lookfile and push to repository
39
+
40
+ status $ lookfile status
41
+ - Show status of files on lookfile
42
+
43
+ show $ lookfile show
44
+ - Show all files that are on lookfile
39
45
 
40
46
  setrepo $ lookfile setrepo [repository_ssh]
41
47
  - Set lookfile repository to save files
data/lib/commands/look.rb CHANGED
@@ -5,6 +5,7 @@ require 'commands/set_repository'
5
5
  require 'commands/push'
6
6
  require 'commands/show'
7
7
  require 'commands/status'
8
+ require 'commands/restore'
8
9
 
9
10
  # Command 'lookfile' implementation
10
11
  class Look < Command
@@ -21,6 +22,6 @@ class Look < Command
21
22
  end
22
23
 
23
24
  def self.childrens
24
- [Init, Add, Push, Status, Show, SetRepository]
25
+ [Init, Add, Push, Status, Show, Restore, SetRepository]
25
26
  end
26
27
  end
data/lib/commands/push.rb CHANGED
@@ -7,7 +7,7 @@ require 'lookfile'
7
7
  class Push < Command
8
8
  def self.options_messages
9
9
  %( push \t\t $ lookfile push
10
- \t\t - Push files on lookfile to repository
10
+ \t\t - Commit files on lookfile and push to repository
11
11
  )
12
12
  end
13
13
 
@@ -0,0 +1,32 @@
1
+ require 'command'
2
+ require 'commands/look'
3
+
4
+ require 'lookfile'
5
+
6
+ # Command 'lookfile restore' implementation
7
+ class Restore < Command
8
+ def self.options_messages
9
+ %( restore \t $ lookfile restore
10
+ \t\t - Restore files from lookfile to user pc
11
+ )
12
+ end
13
+
14
+ def self.command_name
15
+ 'restore'
16
+ end
17
+
18
+ def self.parent
19
+ Look
20
+ end
21
+
22
+ def self.run(*)
23
+ files_path = []
24
+ Lookfile.list_files.each do |file_path|
25
+ print "Restore file #{file_path} (Y/n): "
26
+ option = gets.chomp.upcase
27
+ option = 'Y' if option.empty?
28
+ files_path << file_path if option == 'Y'
29
+ end
30
+ puts Lookfile.restore(files_path)
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Lookfile
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
data/lib/lookfile.rb CHANGED
@@ -30,9 +30,7 @@ module Lookfile
30
30
  end
31
31
 
32
32
  def show(base_dir = BASE_DIR)
33
- lookfile_dir = load_lookfile_dir(base_dir)
34
- files_regex = %r{^#{lookfile_dir}(?!\/.git)(.+)$}
35
- files_path = `find #{lookfile_dir} -type f`.scan(files_regex).flatten
33
+ files_path = list_files(base_dir)
36
34
  show_files('Files on lookfile:', files_path)
37
35
  end
38
36
 
@@ -49,6 +47,19 @@ module Lookfile
49
47
  message
50
48
  end
51
49
 
50
+ def restore(files_path = [], base_dir = BASE_DIR)
51
+ user_path = File.expand_path('~')
52
+ lookfile_dir = load_lookfile_dir(base_dir)
53
+ files_path = [files_path] unless files_path.is_a?(Array)
54
+ message = 'Restore Files:'
55
+ files_path.each do |file|
56
+ path = file.gsub(%r{\/home\/[^\/]+}, user_path)
57
+ folder = path.scan(%r{(.+)+\/}).flatten.first
58
+ message += "\n #{path}" if cp_file(lookfile_dir + file, folder)
59
+ end
60
+ message
61
+ end
62
+
52
63
  def set_repository(repository_ssh_name, base_dir = BASE_DIR)
53
64
  Git.set_remote(repository_ssh_name, base_dir)
54
65
  Git.rebase(base_dir)
@@ -57,15 +68,28 @@ module Lookfile
57
68
  def add_one_file(file_path, base_dir = BASE_DIR)
58
69
  lookfile_dir = load_lookfile_dir(base_dir)
59
70
  folder_path = lookfile_dir + file_path.scan(%r{(.+)\/}).flatten.first
71
+ cp_file(file_path, folder_path)
72
+ end
73
+
74
+ def cp_file(file_path, folder_path)
60
75
  FileUtils.mkpath(folder_path)
61
76
  begin
62
77
  FileUtils.cp(file_path, folder_path)
63
78
  true
64
- rescue
79
+ rescue => error
80
+ puts folder_path
81
+ puts error
65
82
  false
66
83
  end
67
84
  end
68
85
 
86
+ def list_files(base_dir = BASE_DIR)
87
+ lookfile_dir = load_lookfile_dir(base_dir)
88
+ files_regex = %r{^#{lookfile_dir}(?!\/.git)(.+)$}
89
+ files_path = `find #{lookfile_dir} -type f`.scan(files_regex).flatten
90
+ files_path
91
+ end
92
+
69
93
  def show_files(header_message, files_path)
70
94
  message = header_message.to_s unless files_path.empty?
71
95
  files_path.each do |file_path|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Prestes Cavalcanti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-17 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - lib/commands/init.rb
81
81
  - lib/commands/look.rb
82
82
  - lib/commands/push.rb
83
+ - lib/commands/restore.rb
83
84
  - lib/commands/set_repository.rb
84
85
  - lib/commands/show.rb
85
86
  - lib/commands/status.rb
@@ -87,7 +88,6 @@ files:
87
88
  - lib/lookfile.rb
88
89
  - lib/lookfile/version.rb
89
90
  - lookfile.gemspec
90
- - test.rb
91
91
  homepage: https://github.com/LucianoPC/lookfile
92
92
  licenses:
93
93
  - MIT
data/test.rb DELETED
@@ -1 +0,0 @@
1
- aew modified