#!/usr/bin/env ruby require 'trollop' require 'web_translate_it' show_commands = <<-EOS A CLI for syncing files with WebTranslateIt.com Usage: wti [options]+ The most commonly used wti commands are: pull Pull target language file(s) push Push master language file(s) match Display matching of local files with File Manager add Create and push a new master language file rm Delete a master language file from a project addlocale Add a new locale to the project rmlocale Delete a locale from a project status Fetch and display project statistics init Configure your project to sync See `wti --help` for more information on a specific command. [options] are: EOS SUB_COMMANDS = %w(pull push match add addlocale server status st init) global_options = Trollop::options do stop_on SUB_COMMANDS banner show_commands version "Web Translate It v#{WebTranslateIt::Util.version}" end command = ARGV.shift # get the subcommand command_options = case command when "pull" Trollop::options do banner <<-EOS Pull target language file(s) [options] are: EOS opt :locale, "ISO code of locale(s) to pull", :type => :string opt :all, "Pull all files" opt :force, "Force pull (bypass conditional requests to WTI)" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "push" Trollop::options do banner <<-EOS Push master language file(s) [options] are: EOS opt :locale, "ISO code of locale(s) to push", :type => :string opt :all, "Upload all files" opt :force, "Force push (bypass conditional requests to WTI)" opt :low_priority, "WTI will process this file with a low priority" opt :merge, "Force WTI to merge this file" opt :ignore_missing, "Force WTI to not obsolete missing strings" opt :minor, "Minor Changes. When pushing a master file, prevents target translations to be flagged as `to_verify`." opt :label, "Apply a label to the changes", :type => :string opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "add" Trollop::options do banner "Create and push a new master language file" opt :low_priority, "WTI will process this file with a low priority" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "rm" Trollop::options do banner "Delete a master language file" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "addlocale" Trollop::options do banner "Add a new locale to the project" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "rmlocale" Trollop::options do banner "Delete a locale from the project" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "server" Trollop::options do banner <<-EOS Deprecated, used to start a synchronisation server. `gem install web_translate_it_server` and run `wti-server` instead. [options] are: EOS opt :port, "Run server on a specific port", :default => 4000, :short => "-p" opt :host, "Run server on a specific host", :default => "0.0.0.0", :short => "-h" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "status" Trollop::options do banner "Fetch and display project statistics" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "init" Trollop::options do banner "Configure your project to sync" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end when "match" Trollop::options do banner "Display matching of local files with File Manager" opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti" end else if command.nil? puts show_commands exit else Trollop::die "Unknown subcommand #{command.inspect}" end end begin WebTranslateIt::CommandLine.new(command, command_options, global_options, ARGV, File.expand_path(".")) rescue Interrupt => e puts StringUtil.failure("\nQuitting...") exit 1 end