bin/srd in sifttter-redux-0.4.6 vs bin/srd in sifttter-redux-0.4.7
- old
+ new
@@ -31,16 +31,15 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#--------------------------------------------------------------------
require 'gli'
-require 'methadone'
+require 'logger'
require 'sifttter_redux'
require 'securerandom'
include GLI::App
-include Methadone::CLILogging
include SifttterRedux
# ======================================================
# App Info
# ======================================================
@@ -61,36 +60,33 @@
# Pre, Post, and Error
# ======================================================
pre do |global, command, options, args|
# Load SifttterRedux configuration module.
Configuration::load(SRD_CONFIG_FILEPATH)
+
+ # Set up logging.
+ CLIMessage::activate_logging
- # Load Methadone CLILogging module.
- Methadone::CLILogging::change_logger(Methadone::CLILogger.new(SRD_LOG_FILEPATH, SRD_LOG_FILEPATH))
-
if File.exists?(SRD_CONFIG_FILEPATH)
current_version = Gem::Version.new(Configuration['sifttter_redux']['version'])
last_config_change_version = Gem::Version.new(NEWEST_CONFIG_VERSION)
# If the config file needs updating, force the user to do that first.
if Configuration['sifttter_redux']['version'].nil? || current_version < last_config_change_version
CLIMessage::info('This version needs to make some config changes.')
CLIMessage::info("Don't worry; when prompted, your current values for")
CLIMessage::info("existing config options will be presented (so it'll")
CLIMessage::info('be easier to fly through the upgrade).')
- CLIMessage::prompt('Press enter to continue')
+ CLIMessage::prompt('Press enter to continue: ')
SifttterRedux::init(true)
- exit!
+ exit!(0)
end
-
- # Load Dropbox Uploader module.
- DBU.load(Configuration['db_uploader']['exe_filepath'])
else
# Force the user to init if they try to run any command other than `init` first.
CLIMessage::info('Initializing Sifttter Redux first...') unless command.name_for_help[0] == 'init'
SifttterRedux::init
- exit!
+ exit!(0)
end
true
end
@@ -115,39 +111,52 @@
c.switch([:y], desc: 'Run catch-up mode for yesterday')
c.action do |global_options, options, args|
SifttterRedux.verbose = global_options[:verbose] || options[:verbose]
- dates = SifttterRedux::get_dates_from_options(options)
- unless dates.nil?
- first_date = dates.first
- second_date = dates.reverse_each.first
+ begin
+ dates = SifttterRedux::get_dates_from_options(options)
+ unless dates.nil?
+ first_date = dates.first
+ second_date = dates.reverse_each.first
- date_string = first_date.strftime('%B %d, %Y')
- date_string << " to #{ second_date.strftime('%B %d, %Y') }" if first_date != second_date
- CLIMessage::info("Creating #{ first_date == second_date ? 'entry' : 'entries' }: #{ date_string }")
+ date_string = first_date.strftime('%B %d, %Y')
+ date_string << " to #{ second_date.strftime('%B %d, %Y') }" if first_date != second_date
+ CLIMessage::info("Creating #{ first_date == second_date ? 'entry' : 'entries' }: #{ date_string }")
- # Download Sifttter files from Dropbox.
- DBU.local_target = Configuration['sifttter_redux']['sifttter_local_filepath']
- DBU.remote_target = Configuration['sifttter_redux']['sifttter_remote_filepath']
- DBU.message = 'Downloading Sifttter files...'
- DBU.download
+ # Download Sifttter files from Dropbox.
+ dbu = DropboxUploader.new(Configuration['db_uploader']['exe_filepath'])
+ dbu.verbose = SifttterRedux.verbose
+ dbu.local_target = Configuration['sifttter_redux']['sifttter_local_filepath']
+ dbu.remote_target = Configuration['sifttter_redux']['sifttter_remote_filepath']
+ dbu.message = 'Downloading Sifttter files...'
- # Process a new Sifttter entry for each date.
- dates.each do |date|
- Sifttter::run(date)
- end
+ CLIMessage::info_block(dbu.message || dbu::DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
+ dbu.download
+ end
- # Upload any Day One entries to Dropbox (if there are any).
- unless Dir[Configuration['sifttter_redux']['dayone_local_filepath'] + '/*'].empty?
- DBU.local_target = "#{ Configuration['sifttter_redux']['dayone_local_filepath'] }/*"
- DBU.remote_target = Configuration['sifttter_redux']['dayone_remote_filepath']
- DBU.message = 'Uploading Day One entries to Dropbox...'
- DBU.upload
- end
+ # Process a new Sifttter entry for each date.
+ dates.each do |date|
+ Sifttter::run(date)
+ end
- # Remove any downloaded local files that we no longer need.
- SifttterRedux::cleanup_temp_files
+ # Upload any Day One entries to Dropbox (if there are any).
+ unless Dir[Configuration['sifttter_redux']['dayone_local_filepath'] + '/*'].empty?
+ dbu.local_target = "#{ Configuration['sifttter_redux']['dayone_local_filepath'] }/*"
+ dbu.remote_target = Configuration['sifttter_redux']['dayone_remote_filepath']
+ dbu.message = 'Uploading Day One entries to Dropbox...'
+
+ CLIMessage::info_block(dbu.message || dbu::DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
+ dbu.upload
+ end
+ end
+
+ # Remove any downloaded local files that we no longer need.
+ SifttterRedux::cleanup_temp_files
+ end
+ rescue StandardError => e
+ CLIMessage::error(e.to_s)
+ exit!(1)
end
end
end