This repository was archived by the owner on Feb 23, 2021. It is now read-only.
forked from slackhq/magic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommando-masterize
56 lines (44 loc) · 1.8 KB
/
commando-masterize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby
require_relative 'commando-helpers.rb'
program :description, 'Takes a batch of AEP working files and copies newest to masters folder'
program :version, '1.0.0'
command :run do |c|
c.description = ''
c.option '--input DIR', String, 'Input directory of shots, each containing incremental versions'
c.option '--glob GLOB', String, 'Input file search glob'
c.option '--output DIR', String, 'Output directory'
c.action do |args, options|
options.default \
input: "./",
glob: "*.aep",
output: "./masters"
options.input = File.expand_path(options.input)
options.output = File.expand_path(options.output)
command_header(c, options)
if ! File.directory?(options.input)
crash "Input directory '#{options.input}' does not exist"
end
if ! File.directory?(options.output)
crash "Output directory '#{options.output}' does not exist"
end
if Dir.glob("#{options.input}/*/#{options.glob}").length == 0
crash "#{options.input} does not contain any sub-directories containing #{options.glob} files"
end
Dir.glob("#{options.input}/*") do |shot|
# sort input like "foo.bar, foo-02.bar, foo-03.bar" with suffixless first
files = Dir.glob("#{shot}/#{options.glob}").sort_by do |file|
filename = File.basename(file, File.extname(file))
filename.rpartition('-').last.to_i
end
unless files.last
puts "Skipping #{@pastel.bright_yellow shot}, does not contain any #{options.glob} files."
next
end
newest = files.last.clone
master = "#{options.output}/#{File.basename(shot.clone)}-master#{File.extname(newest)}"
puts "Copying #{@pastel.bright_blue newest} to #{@pastel.green master}..."
FileUtils.copy_file(newest, master)
end
end
end
default_command :run