bin/revenc in revenc-0.1.3 vs bin/revenc in revenc-0.2.1
- old
+ new
@@ -1,9 +1,10 @@
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + '/../lib')
+require 'rubygems'
require 'revenc'
require 'optparse'
require 'term/ansicolor'
available_actions = Revenc::AVAILABLE_ACTIONS
@@ -16,32 +17,33 @@
banner << "\nActions: #{available_actions.join(' ')}\n" unless available_actions.empty?
help = banner
help += <<HELP
Mount: revenc mount <unencrypted source> <empty mountpoint>
-Unmount: revenc unmount <mounted encypted folder>
+Unmount: revenc unmount <mounted encypted folder>
Copy: revenc copy <encrypted source> <destination>
Note: Copying is normally done via rsync
Options:
-
+
HELP
options = {}
OptionParser.new do |opts|
opts.banner = help
- # set defaults
- options[:verbose] = false
- options[:coloring] = true
-
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
- opts.on("-c", "--[no-]coloring", "Ansi color in output") do |c|
- options[:coloring] = c
+ opts.on("-c", "--[no-]coloring [MODE]", "ANSI color in output. MODE=AUTO (default) or ALWAYS") do |c|
+ options[:coloring] = c.nil? ? "AUTO" : c
+ options[:coloring].upcase! if options[:coloring]
+ unless [nil, false, "AUTO", "ALWAYS"].include?(options[:coloring])
+ puts "revenc, invalid color option: #{options[:coloring]}"
+ exit 1
+ end
end
opts.on("--version", "Display current version") do
puts "revenc, version " + Revenc.version
exit 0
@@ -50,32 +52,47 @@
opts.on("-d", "--dry-run", "Run action but omit the final execute step. Useful combined with --verbose") do |d|
options[:dry_run] = d
end
opts.on("--config FILE", "Load configuration options from FILE") do |file|
- options[:config] = file
+ options[:config] = file
end
# no argument, shows at tail. This will print an options summary.
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit 0
end
-
+
begin
opts.parse!
rescue OptionParser::InvalidOption => e
puts "revenc #{e}"
puts "revenc --help for more information"
exit 1
end
end
-if STDOUT.isatty
+# options from config file, if it exists, will not overwrite command line
+options = Revenc::Settings.new(FileUtils.pwd, options).options
+
+if STDOUT.isatty || (options[:coloring] == 'ALWAYS')
Term::ANSIColor::coloring = options[:coloring]
+
+ if options[:coloring] && Revenc::WINDOWS
+ unless ENV['ANSICON']
+ begin
+ require 'Win32/Console/ANSI'
+ rescue LoadError
+ Term::ANSIColor::coloring = false
+ STDERR.puts 'WARNING: You must "gem install win32console" (1.2.0 or higher) or use the ANSICON driver (https://github.com/adoxa/ansicon) to get color output on MRI/Windows'
+ end
+ end
+ end
+
else
Term::ANSIColor::coloring = false
end
-app = Revenc::App.new(FileUtils.pwd, options)
-app.run
+app = Revenc::App.new(FileUtils.pwd, ARGV.dup, options)
+app.execute