bak 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d511bf4ec46e0a76e74b1ee7713a8b4d6cac462
4
- data.tar.gz: 51b1ef8b67f7b88ddf4d40a5867dcabb6e5cfdc3
3
+ metadata.gz: 2b6c64c6d82f2fef02482b8177135f00c76cc57a
4
+ data.tar.gz: 20d1b920ce53ea9b114ed6e5dfeaf934ebf82efd
5
5
  SHA512:
6
- metadata.gz: c6fa1b9ee4c596bd74572ee7b1778a83f418f5f56b60fcfd7ce17da15cffc8015f8437148623aba36ac813e9590cd136e47c0c0de55432f48f143020b6bb1f62
7
- data.tar.gz: e3e2b8882d92c0d7435c0e88c52032c08a1900cdde1b05d0f958c0dca9367330c6269558f08eac96abddbe15368b463fabe7831922a950170e1d3c00c7049c4c
6
+ metadata.gz: e30262bbce3c45844eab13a7df5c1db2f4ead61b7f7cc2dc76385832d306b89722f83c0d9728d7f254e45e08d2ce34c08d1d9ca247a4c4aa2c7d228a74250c9f
7
+ data.tar.gz: e14294bdaa108ebdcbd54c13803d6ff4e29a46c63deef3dc4c91234a16aed49bc5fbdf643ddcf4fd81f96e3042b15cc87457c59177de95e70f5744356af1751b
data/bin/bak CHANGED
@@ -27,6 +27,14 @@ option_parser = OptionParser.new do |opts|
27
27
  options[:prefix] = prefix
28
28
  end
29
29
 
30
+ opts.on("-t TARGETPATH") do |path|
31
+ options[:target_path] = path
32
+ end
33
+
34
+ opts.on("-c", "--create") do
35
+ options[:create_path] = true
36
+ end
37
+
30
38
  opts.on("-R TEXT") do |text|
31
39
  options[:replace] ||= {}
32
40
  patternCount += 1
@@ -40,6 +48,12 @@ option_parser.parse!
40
48
  options[:force] ||= false
41
49
  options[:no_bak] ||= false
42
50
 
51
+ # make sure the create option is always paired with the target_path option
52
+ if options[:create_path] && !options[:target_path]
53
+ STDERR.puts("please specify target directory to create with the -t option")
54
+ exit 1
55
+ end
56
+
43
57
  if ARGV.length > 0
44
58
  filenames = ARGV
45
59
  else
@@ -22,6 +22,7 @@ module Bak
22
22
  if @options[:postfix] then filename = _with_postfix(filename, @options[:postfix]) end
23
23
  if @options[:prefix] then filename = _with_prefix(filename, @options[:prefix]) end
24
24
  if @options[:replace] then filename = _with_replace(filename, @options[:replace]) end
25
+ if @options[:target_path] then filename = _with_target_path(filename, @options[:target_path]) end
25
26
  end
26
27
  unless @options[:no_bak] then filename = "#{filename}.bak" end
27
28
 
@@ -47,6 +48,10 @@ module Bak
47
48
  return filename.gsub(pattern, replace)
48
49
  end
49
50
 
51
+ def _with_target_path(filename, target_path)
52
+ return "#{target_path}/#{filename}"
53
+ end
54
+
50
55
  def _get_date
51
56
  return Time.new.strftime("%Y-%m-%d")
52
57
  end
@@ -15,6 +15,12 @@ module Bak
15
15
  if File.exists?(@end_file) && !@generator[:force]
16
16
  return "#{end_file}: File already exists"
17
17
  end
18
+ if @generator[:create_path] == true
19
+ FileUtils::mkdir_p @generator[:target_path]
20
+ end
21
+ if @generator[:target_path] && !File.directory?(@generator[:target_path])
22
+ return "#{@generator[:target_path]} directory does not exist"
23
+ end
18
24
  end
19
25
 
20
26
  def start
@@ -1,3 +1,3 @@
1
1
  module Bak
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Freidah