Class: Commandline

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/babelish_rnc/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)


176
177
178
# File 'lib/babelish_rnc/commandline.rb', line 176

def self.exit_on_failure?
  true
end

Instance Method Details

#csv_downloadObject

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
# File 'lib/babelish_rnc/commandline.rb', line 71

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



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/babelish_rnc/commandline.rb', line 96

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

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



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/babelish_rnc/commandline.rb', line 83

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

#versionObject



112
113
114
115
# File 'lib/babelish_rnc/commandline.rb', line 112

def version
  require "babelish_rnc/version"
  say "babelish_rnc #{BabelishRnc::VERSION}"
end