Class: Commandline

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/babelish/commandline.rb

Constant Summary collapse

CSVCLASSES =
[
  {:name => "CSV2Strings", :ext => ".strings"},
  {:name => "CSV2Android", :ext => ".xml"},
  {:name => "CSV2JSON", :ext => ".json"},
  {:name => "CSV2Php", :ext => ".php"},
]
BASECLASSES =
[
  {:name => "Strings2CSV", :ext => ".strings"},
  {:name => "Android2CSV", :ext => ".xml"},
  {:name => "JSON2CSV", :ext => ".json"},
  {:name => "Php2CSV", :ext => ".php"},
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/babelish/commandline.rb', line 171

def self.exit_on_failure?
  true
end

Instance Method Details

#csv_downloadObject

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
# File 'lib/babelish/commandline.rb', line 66

def csv_download
  all = options[:sheet] ? false : options[:all]
  filename = options['gd_filename']
  raise ArgumentError.new("csv_download command : missing file to download") unless filename
  if all
    download(filename)
  else
    download(filename, options['output_filename'], options['sheet'])
  end
end

#initObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/babelish/commandline.rb', line 91

def init
  if File.exists?(".babelish")
    say "Config file '.babelish' already exists."
  else
    say "Creating new config file '.babelish'."
    config_file = File.expand_path("../../../.babelish.sample", __FILE__)
    if File.exists?(config_file)
      system "cp #{config_file} .babelish"
    else
      say "Template '#{config_file}' not found."
    end
  end
end

#open(file = "translations.csv") ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/babelish/commandline.rb', line 78

def open(file = "translations.csv")
  filename = file || options["filename"]
  if File.exists?(filename)
    say "Opening local file '#{filename}'"
    system "open \"#{filename}\""
  else
    say "Opening Google Drive file '#{filename}'"
    gd = Babelish::GoogleDoc.new
    gd.open filename.to_s
  end
end

#versionObject



107
108
109
110
# File 'lib/babelish/commandline.rb', line 107

def version
  require "babelish/version"
  say "Babelish #{Babelish::VERSION}"
end