#!/usr/bin/env ruby require 'csv' require 'expandsync' require 'methadone' require 'nokogiri' require 'optparse' class App include Methadone::Main include Methadone::CLILogging main do |atext_filepath| begin # Collect snippets from both aText and TextExpander and create an # array with the unique entries of both. atext = AText.new(atext_filepath) textexpander = TextExpander.new(options[:t] || ExpandSync::DEFAULT_TE_SNIPPET_PATH) combined_snippets = (atext.snippets + textexpander.snippets).uniq { |s| s[0] } # Next, create file content (CSV for aText, XML for TextExpander) # that contains the correct data: # 1. aText CSV should contain any new TextExpander snippets. # 2. TextExpander XML should contain original snippets *and* # any new aText snippets. new_at_csv = atext.construct_data(combined_snippets - atext.snippets) new_te_xml = textexpander.construct_data(combined_snippets - textexpander.snippets) # Save new aText snippets File.open(options[:a] || ExpandSync::DEFAULT_AT_OUTPUT_PATH, 'w') {|f| f.write(new_at_csv) } # Backup the original TextExpander file and output the new one. FileUtils.cp(ExpandSync::DEFAULT_TE_SNIPPET_PATH, ExpandSync::DEFAULT_TE_SNIPPET_PATH + '.bak') File.open(ExpandSync::DEFAULT_TE_SNIPPET_PATH, 'w') {|f| f.write(new_te_xml) } # This has to be here so that my Cucumber Aruba tests work. Don't ask why. leak_exceptions(true) rescue StandardError => e ExpandSync::CLIMessage.error(e, false) end end description ExpandSync::DESCRIPTION version ExpandSync::VERSION # Flags & Switches on('-a FILEPATH', "Specify an output location for aText rules (default to...})") on('-n', ) on('-t FILEPATH', 'Specify a location for the TextExpander iOS XML file') on('-v', '--verbose', 'Turn on verbose output') # Arguments arg :atext_filepath, 'The filepath to a CSV file exported from aText' go! end