collapse 0.0.1
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.
- data/lib/collapse.rb +52 -0
- metadata +66 -0
data/lib/collapse.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
def collapse_dir(target_dir, destination_dir)
|
7
|
+
# Moves all of the files from target_dir into destination_dir and
|
8
|
+
# then removes target_dir
|
9
|
+
FileUtils.mkdir destination_dir if not File.directory?(destination_dir)
|
10
|
+
FileUtils.mv Dir.glob("#{target_dir}/*"), destination_dir
|
11
|
+
FileUtils.remove_dir target_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
def collapse(target_dir, destination_dir, recursively)
|
15
|
+
if recursively
|
16
|
+
Dir.foreach(target_dir) do |item|
|
17
|
+
next if item == '.' or item == '..'
|
18
|
+
path = "#{target_dir}/#{item}"
|
19
|
+
if File.directory?(path)
|
20
|
+
collapse path, target_dir, recursively
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
temporary_storage = "#{destination_dir}/.ko"
|
26
|
+
collapse_dir target_dir, temporary_storage
|
27
|
+
collapse_dir temporary_storage, destination_dir
|
28
|
+
end
|
29
|
+
|
30
|
+
def run()
|
31
|
+
options = {}
|
32
|
+
option_parser = OptionParser.new do |opts|
|
33
|
+
opts.banner = "usage: #{File.basename($PROGRAM_NAME)} [-r] target_dir\n\n"
|
34
|
+
opts.on(
|
35
|
+
'-r',
|
36
|
+
'--recursively',
|
37
|
+
'collapse entire directory tree'
|
38
|
+
) do
|
39
|
+
options[:recursively] = true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
option_parser.parse!
|
43
|
+
if ARGV.empty?
|
44
|
+
puts option_parser.help
|
45
|
+
else
|
46
|
+
target_dir = ARGV[0]
|
47
|
+
|
48
|
+
collapse target_dir, '.', options[:recursively]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
run
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collapse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Avila
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-06-10 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Collapse directories
|
22
|
+
email:
|
23
|
+
- me at michaelavila.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/collapse.rb
|
32
|
+
homepage: http://github.com/michaelavila/collapse
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: collapse
|
61
|
+
rubygems_version: 1.8.25
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Collapse directories
|
65
|
+
test_files: []
|
66
|
+
|