filedepot 0.2.1 → 0.2.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
  SHA256:
3
- metadata.gz: 3323f568d221fde7de4cd30f7450b46444f48bcfe71b2e0dd16acfe84d97fd14
4
- data.tar.gz: 39318899de695422ef75292f4e5c5a8cf3271b91ef0d474fdc1305ebfd78dead
3
+ metadata.gz: 2e67db1d2be17a3af457047eb147926143e85ce7a41f398ff818fc83c404dcfa
4
+ data.tar.gz: 3a6616e9a4925732d04d78f55fb716127c115d63220b673165795beba8b9d9c7
5
5
  SHA512:
6
- metadata.gz: 37f23733b8942db6547ab12960cef9308717f1836ff4c1ae6959c3a1196c00195508f4a5d996d8b9efd10a7ac93552799d633fa11e475f6575ddccee690985ee
7
- data.tar.gz: 70f21d4037d84be1cc71c12032eb7e31253b304511af80e8d6fb7e397823e87a9c4718db35466bfe746ca3cfc249a089bc65e534d1e3330240196a5dc703c8a0
6
+ metadata.gz: 42946b05448b6bf6c3db84b7a8c372a8f5e61688ed63defa263401ac67273d74ef647b0642e52277515d1ae2910c17fcda810b5f7da965eb5b2855bbf2913409
7
+ data.tar.gz: d11483ddbf5f480956a7ae334e5bd238ff701e77e198d259b825db077ae1961c844cbd71e50a8cc04ac6cb39899884ad37688e598fcd91bc534d9bc1baec6872
data/README.md CHANGED
@@ -30,17 +30,65 @@ sources:
30
30
  base_path: /Users/user/filedepot
31
31
  ```
32
32
 
33
+ Optional `public_base_path` for public URLs (shown in info and after push):
34
+
35
+ ```yaml
36
+ sources:
37
+ - name: test
38
+ ssh: ssh
39
+ host: 127.0.0.1
40
+ base_path: /data/filedepot
41
+ public_base_path: https://example.com/files
42
+ ```
43
+
44
+ When `default_source` does not match any source name, the first source is used.
45
+
33
46
  ## Commands
34
47
 
35
48
  | Command | Description |
36
49
  |---------|-------------|
37
50
  | `filedepot` | Show current source and available commands |
38
51
  | `filedepot config` | Open config file with $EDITOR |
39
- | `filedepot push HANDLE` | Send file to current storage |
40
- | `filedepot pull HANDLE [VERSION]` | Get file from storage |
52
+ | `filedepot push HANDLE FILE` | Send file to current storage |
53
+ | `filedepot pull HANDLE [--path PATH] [--version N]` | Get file from storage |
41
54
  | `filedepot versions HANDLE` | List all versions of a handle |
55
+ | `filedepot info HANDLE` | Show info for a handle |
42
56
  | `filedepot delete HANDLE [VERSION]` | Delete file(s) after confirmation |
43
57
 
58
+ ### Push
59
+
60
+ ```bash
61
+ filedepot push test test.txt
62
+ ```
63
+
64
+ Sends `test.txt` to storage with handle `test`. Each push creates a new version. When `public_base_path` is configured, the URL is shown after upload.
65
+
66
+ ### Pull
67
+
68
+ ```bash
69
+ filedepot pull test
70
+ filedepot pull test --path ./output/file.txt
71
+ filedepot pull test --version 2
72
+ filedepot pull test --version 2 --path ./output/file.txt
73
+ ```
74
+
75
+ Gets the latest version by default, or a specific version with `--version`. Use `--path` to specify the local destination. Prompts before creating directories or overwriting files.
76
+
77
+ ### Versions
78
+
79
+ Lists versions in descending order with creation datetime. Shows at most 10, with a summary if more exist.
80
+
81
+ ### Info
82
+
83
+ Shows handle, remote base path, current version, updated-at datetime, and latest version URL (when `public_base_path` is set).
84
+
85
+ ## Testing
86
+
87
+ ```bash
88
+ bundle install
89
+ bundle exec rake test
90
+ ```
91
+
44
92
  ## License
45
93
 
46
94
  MIT
data/lib/filedepot/cli.rb CHANGED
@@ -50,6 +50,20 @@ module Filedepot
50
50
 
51
51
  desc "push HANDLE FILE", "Send a file to the current storage with a specific handle"
52
52
  def push(handle, file_path)
53
+ if handle.to_s.strip.empty?
54
+ puts "Error: Handle is required."
55
+ return
56
+ end
57
+ if file_path.to_s.strip.empty?
58
+ puts "Error: File path is required."
59
+ return
60
+ end
61
+ path = File.expand_path(file_path)
62
+ unless File.file?(path)
63
+ puts "Error: File not found: #{path}"
64
+ return
65
+ end
66
+
53
67
  source = Config.current_source
54
68
  if source.nil?
55
69
  puts "Error: No storage source configured. Run 'filedepot config' to set up."
@@ -57,11 +71,13 @@ module Filedepot
57
71
  end
58
72
 
59
73
  storage = Storage::Base.for(source)
60
- storage.push(handle, file_path)
74
+ storage.push(handle, path)
61
75
  version = storage.current_version(handle)
62
76
  puts "Pushed #{file_path} as #{handle} (version #{version})"
63
- uploaded_url = storage.url(handle, version, File.basename(file_path))
77
+ uploaded_url = storage.url(handle, version, File.basename(path))
64
78
  puts uploaded_url if uploaded_url
79
+ rescue RuntimeError => e
80
+ puts "Error: #{e.message}"
65
81
  end
66
82
 
67
83
  desc "pull HANDLE", "Get file from storage"
@@ -100,6 +116,8 @@ module Filedepot
100
116
 
101
117
  storage.pull(handle, version, target_path)
102
118
  puts "pulled to #{target_path}"
119
+ rescue RuntimeError => e
120
+ puts "Error: #{e.message}"
103
121
  end
104
122
 
105
123
  desc "versions HANDLE", "List all versions of a handle (each version has an integer from 1 to n)"
@@ -118,7 +136,7 @@ module Filedepot
118
136
  storage = Storage::Base.for(source)
119
137
  versions_list = storage.versions(handle)
120
138
  if versions_list.empty?
121
- puts "No versions found for handle: #{handle}"
139
+ puts "Error: Handle '#{handle}' not found."
122
140
  else
123
141
  max_display = 10
124
142
  to_show = versions_list.first(max_display)
@@ -144,6 +162,12 @@ module Filedepot
144
162
  end
145
163
 
146
164
  storage = Storage::Base.for(source)
165
+ versions_list = storage.versions(handle)
166
+ if versions_list.empty?
167
+ puts "Error: Handle '#{handle}' not found."
168
+ return
169
+ end
170
+
147
171
  data = storage.info(handle)
148
172
 
149
173
  puts "handle: #{data[:handle]}"
@@ -159,8 +183,46 @@ module Filedepot
159
183
  puts COMMAND_HELP[:delete]
160
184
  return
161
185
  end
186
+
187
+ source = Config.current_source
188
+ if source.nil?
189
+ puts "Error: No storage source configured. Run 'filedepot config' to set up."
190
+ return
191
+ end
192
+
193
+ storage = Storage::Base.for(source)
194
+ versions_list = storage.versions(handle)
195
+ if versions_list.empty?
196
+ puts "Error: Handle '#{handle}' not found."
197
+ return
198
+ end
199
+ if version
200
+ version_nums = versions_list.map(&:first)
201
+ unless version_nums.include?(version.to_i)
202
+ puts "Error: Version #{version} not found for handle '#{handle}'."
203
+ return
204
+ end
205
+ end
206
+
162
207
  version_str = version ? " version #{version}" : " all versions"
163
- puts "delete: would delete file '#{handle}'#{version_str} after confirmation (not implemented)"
208
+ puts "This will delete '#{handle}'#{version_str}."
209
+ begin
210
+ print "Type the handle name to confirm: "
211
+ input = $stdin.gets&.strip
212
+ rescue Interrupt
213
+ puts
214
+ return
215
+ end
216
+
217
+ unless input == handle
218
+ puts "Aborted (handle name did not match)."
219
+ return
220
+ end
221
+
222
+ storage.delete(handle, version)
223
+ puts "Deleted #{handle}#{version ? " version #{version}" : ""}."
224
+ rescue RuntimeError => e
225
+ puts "Error: #{e.message}"
164
226
  end
165
227
 
166
228
  default_task :default
@@ -74,10 +74,11 @@ module Filedepot
74
74
  end
75
75
 
76
76
  def url(handle, version, filename)
77
- base = @source["public_base_path"].to_s.sub(%r{/$}, "")
77
+ base = @source["public_base_path"].to_s.sub(%r{/+$}, "")
78
78
  return nil if base.empty? || filename.nil? || filename.empty?
79
79
 
80
- [base, handle, version, filename].join("/").gsub(%r{/+}, "/")
80
+ path = [handle, version, filename].join("/")
81
+ "#{base}/#{path}"
81
82
  end
82
83
 
83
84
  protected
@@ -27,7 +27,7 @@ module Filedepot
27
27
 
28
28
  def push(handle, local_path)
29
29
  path = File.expand_path(local_path)
30
- raise "File not found: #{local_path}" unless File.file?(path)
30
+ raise "File not found: #{path}" unless File.file?(path)
31
31
 
32
32
  push_path = next_version_path(handle)
33
33
 
@@ -57,14 +57,14 @@ module Filedepot
57
57
  def pull(handle, version = nil, local_path = nil)
58
58
  ssh_session do |ssh|
59
59
  versions_list = versions_for(ssh, handle)
60
- raise "No versions found for handle: #{handle}" if versions_list.empty?
60
+ raise "Handle '#{handle}' not found" if versions_list.empty?
61
61
 
62
62
  version_num = version ? version.to_i : versions_list.max
63
- raise "Version #{version} not found" unless versions_list.include?(version_num)
63
+ raise "Version #{version} not found for handle '#{handle}'" unless versions_list.include?(version_num)
64
64
 
65
65
  version_dir = File.join(remote_handle_path(handle), version_num.to_s)
66
66
  remote_file = first_file_in_dir(ssh, version_dir)
67
- raise "No file found in version #{version_num}" if remote_file.nil?
67
+ raise "No file found in version #{version_num} for handle '#{handle}'" if remote_file.nil?
68
68
 
69
69
  remote_filename = File.basename(remote_file)
70
70
  target_path = resolve_local_path(local_path, remote_filename)
@@ -77,14 +77,14 @@ module Filedepot
77
77
  def pull_info(handle, version = nil, local_path = nil)
78
78
  ssh_session do |ssh|
79
79
  versions_list = versions_for(ssh, handle)
80
- raise "No versions found for handle: #{handle}" if versions_list.empty?
80
+ raise "Handle '#{handle}' not found" if versions_list.empty?
81
81
 
82
82
  version_num = version ? version.to_i : versions_list.max
83
- raise "Version #{version} not found" unless versions_list.include?(version_num)
83
+ raise "Version #{version} not found for handle '#{handle}'" unless versions_list.include?(version_num)
84
84
 
85
85
  version_dir = File.join(remote_handle_path(handle), version_num.to_s)
86
86
  remote_file = first_file_in_dir(ssh, version_dir)
87
- raise "No file found in version #{version_num}" if remote_file.nil?
87
+ raise "No file found in version #{version_num} for handle '#{handle}'" if remote_file.nil?
88
88
 
89
89
  remote_filename = File.basename(remote_file)
90
90
  target_path = resolve_local_path(local_path, remote_filename)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Filedepot
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filedepot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filedepot