From 638ba097ab7c994558daa6342e914db0721580a2 Mon Sep 17 00:00:00 2001 From: "Brian D. Burns" Date: Mon, 18 Feb 2013 23:52:04 -0500 Subject: [PATCH] Backup::CLI::Utility -> Backup::CLI --- bin/backup | 8 +- lib/backup.rb | 9 +- lib/backup/cli.rb | 310 +++++++++++++++++++++ lib/backup/cli/utility.rb | 312 ---------------------- lib/backup/logger.rb | 2 +- spec/{cli/utility_spec.rb => cli_spec.rb} | 8 +- 6 files changed, 317 insertions(+), 332 deletions(-) create mode 100644 lib/backup/cli.rb delete mode 100644 lib/backup/cli/utility.rb rename spec/{cli/utility_spec.rb => cli_spec.rb} (99%) diff --git a/bin/backup b/bin/backup index fc16410b2..125c0fb78 100755 --- a/bin/backup +++ b/bin/backup @@ -1,11 +1,5 @@ #!/usr/bin/env ruby # encoding: utf-8 -# Load the Backup core library require File.expand_path("../../lib/backup", __FILE__) - -# Load the Backup command line interface utility -require File.expand_path("../../lib/backup/cli/utility", __FILE__) - -# Initialize the Backup command line utility -Backup::CLI::Utility.start +Backup::CLI.start diff --git a/lib/backup.rb b/lib/backup.rb index f0cdf66a3..a954c66ad 100644 --- a/lib/backup.rb +++ b/lib/backup.rb @@ -18,7 +18,6 @@ module Backup ## # Backup's internal paths LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup') - CLI_PATH = File.join(LIBRARY_PATH, 'cli') STORAGE_PATH = File.join(LIBRARY_PATH, 'storage') DATABASE_PATH = File.join(LIBRARY_PATH, 'database') COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor') @@ -27,12 +26,6 @@ module Backup SYNCER_PATH = File.join(LIBRARY_PATH, 'syncer') TEMPLATE_PATH = File.expand_path('../../templates', __FILE__) - ## - # Autoload Backup CLI files - module CLI - autoload :Utility, File.join(CLI_PATH, 'utility') - end - ## # Autoload Backup storage files module Storage @@ -100,7 +93,6 @@ module Encryptor # Autoload notification files module Notifier autoload :Base, File.join(NOTIFIER_PATH, 'base') - autoload :Binder, File.join(NOTIFIER_PATH, 'binder') autoload :Mail, File.join(NOTIFIER_PATH, 'mail') autoload :Twitter, File.join(NOTIFIER_PATH, 'twitter') autoload :Campfire, File.join(NOTIFIER_PATH, 'campfire') @@ -117,6 +109,7 @@ module Notifier binder cleaner config + cli configuration dependency errors diff --git a/lib/backup/cli.rb b/lib/backup/cli.rb new file mode 100644 index 000000000..7383caa43 --- /dev/null +++ b/lib/backup/cli.rb @@ -0,0 +1,310 @@ +# encoding: utf-8 + +## +# Build the Backup Command Line Interface using Thor +module Backup + class CLI < Thor + include Thor::Actions + + ## + # [Perform] + # Performs the backup process. The only required option is the --trigger [-t]. + # If the other options (--config-file, --data-path, --cache-path, --tmp-path) aren't specified + # they will fallback to the (good) defaults + # + # If --root-path is given, it will be used as the base path for our defaults, + # as well as the base path for any option specified as a relative path. + # Any option given as an absolute path will be used "as-is". + desc 'perform', "Performs the backup for the specified trigger(s)." + long_desc "Performs the backup for the specified trigger(s).\n\n" + + "You may perform multiple backups by providing multiple triggers, separated by commas.\n\n" + + "Example:\n\s\s$ backup perform --triggers backup1,backup2,backup3,backup4\n\n" + + "This will invoke 4 backups, and they will run in the order specified (not asynchronous).\n\n" + + "\n\n" + + "--root-path may be an absolute path or relative to the current working directory.\n\n" + + "To use the current directory, you can use: `--root-path .` (i.e. a period for the argument)" + + method_option :trigger, :type => :string, :required => true, :aliases => ['-t', '--triggers'], + :desc => "Triggers to perform. e.g. 'trigger_a,trigger_b'" + method_option :config_file, :type => :string, :default => '', :aliases => '-c', + :desc => "Path to your config.rb file. " + + "Absolute, or relative to --root-path." + method_option :root_path, :type => :string, :default => '', :aliases => '-r', + :desc => "Root path to base all relative path on. " + + "Absolute or relative to current directory (#{Dir.pwd})." + method_option :data_path, :type => :string, :default => '', :aliases => '-d', + :desc => "Path to store persisted data (storage 'keep' data). " + + "Absolute, or relative to --root-path." + method_option :log_path, :type => :string, :default => '', :aliases => '-l', + :desc => "Path to store Backup's log file. " + + "Absolute, or relative to --root-path." + method_option :cache_path, :type => :string, :default => '', + :desc => "Path to store Dropbox's cached authorization. " + + "Absolute, or relative to --root-path." + method_option :tmp_path, :type => :string, :default => '', + :desc => "Path to store temporary data during the backup process. " + + "Absolute, or relative to --root-path." + # Note that :quiet, :syslog and :logfile are specified as :string types, + # so the --no-