diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2015-12-02 12:52:38 +0000 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2015-12-02 12:52:38 +0000 |
commit | 9eb0ccb29bf74816f53ee100805c53e10435112e (patch) | |
tree | 4ce8501f2bbbfc6a4a6948381040dc397f6f639e /bin | |
parent | d7d1548e7c07369247571a939b0c1838f1c2ee75 (diff) |
Tidied up trollop options.
Including checking that only one of --complete, --ping, or --list are
called.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/byteback-receive | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/bin/byteback-receive b/bin/byteback-receive index c80068b..d6fce81 100755 --- a/bin/byteback-receive +++ b/bin/byteback-receive @@ -102,24 +102,32 @@ elsif ARGV[0] == "restore" end opts = Trollop.options do - opt :verbose, 'Print diagnostics' opt :ping, 'Check connection parameters and exit' + opt :complete, 'Mark current backup as complete' opt :list, 'Show backed up files matching the given pattern' - opt :list_all, 'Show all stored versions of a file' + opt :all, 'Show all stored versions of a file' opt :snapshot, 'Show backed up files in a certain snapshot.', :default => '*' - opt :restore, 'Perform a restoration operation', :type => :string - opt :complete, 'Mark current backup as complete' + opt :verbose, 'Print diagnostics' +end + +# +# Make sure we don't get crazy option combinations. +# +n_modes = opts.keys.inject(0) do |s,m| + s += 1 if [:ping, :complete, :list].include?(m) end -error('Please only choose one mode') if opts[:ping] && opts[:complete] +error('Please only choose one mode') unless n_modes == 1 + if opts[:complete] system('byteback-snapshot', '--root', byteback_root) + elsif opts[:list] args = Byteback::Restore.decode_args(ARGV[1..-1]) restore = Byteback::Restore.new(byteback_root) restore.snapshot = opts[:snapshot] - restore.find(args, :all => opts[:list_all], :verbose => opts[:verbose]) + restore.find(args, :all => opts[:all], :verbose => opts[:verbose]) if restore.results.empty? puts "** Sorry. There were no files matching:" @@ -127,10 +135,14 @@ elsif opts[:list] else puts restore.list end + exit(0) + elsif opts[:ping] exit 0 + else STDERR.print "byteback-receive failed\n" exit 9 + end |