lib/i18n-js/cli/export_command.rb in i18n-js-4.0.0.alpha3 vs lib/i18n-js/cli/export_command.rb in i18n-js-4.0.0.alpha4
- old
+ new
@@ -12,11 +12,11 @@
opts.banner = "Usage: i18n #{name} [options]"
opts.on(
"-cCONFIG_FILE",
"--config=CONFIG_FILE",
- "The configuration file that will be generated"
+ "The configuration file that will be used"
) do |config_file|
options[:config_file] = config_file
end
opts.on(
@@ -33,20 +33,19 @@
end
command do
set_defaults!
- ui.stdout_print("=> config file:", options[:config_file].inspect)
- ui.stdout_print("=> require file:", options[:require_file].inspect)
-
unless options[:config_file]
ui.fail_with("=> ERROR: you need to specify the config file")
end
+ ui.stdout_print("=> Config file:", options[:config_file].inspect)
config_file = File.expand_path(options[:config_file])
if options[:require_file]
+ ui.stdout_print("=> Require file:", options[:require_file].inspect)
require_file = File.expand_path(options[:require_file])
end
unless File.file?(config_file)
ui.fail_with(
@@ -65,44 +64,18 @@
time = Benchmark.realtime do
load_require_file!(require_file) if require_file
I18nJS.call(config_file: config_file)
end
- ui.stdout_print("=> done in #{time.round(2)}s")
+ ui.stdout_print("=> Done in #{time.round(2)}s")
end
private def set_defaults!
config_file = "./config/i18n.yml"
require_file = "./config/environment.rb"
options[:config_file] ||= config_file if File.file?(config_file)
options[:require_file] ||= require_file if File.file?(require_file)
- end
-
- private def load_require_file!(require_file)
- require_without_warnings(require_file)
- rescue Exception => error # rubocop:disable Lint/RescueException
- ui.stderr_print("=> ERROR: couldn't load",
- options[:require_file].inspect)
- ui.fail_with(
- "\n#{error_description(error)}\n#{error.backtrace.join("\n")}"
- )
- end
-
- private def error_description(error)
- [
- error.class.name,
- error.message
- ].reject(&:empty?).join(" => ")
- end
-
- private def require_without_warnings(path)
- old_verbose = $VERBOSE
- $VERBOSE = nil
-
- require path
- ensure
- $VERBOSE = old_verbose
end
end
end
end