Skip to content
Browse files

fixes #16

  • Loading branch information...
1 parent 7e4052b commit 5bb237abeacdd64f3435c316e0629eae87a05a49 @shaiguitar committed
Showing with 29 additions and 18 deletions.
  1. +3 −17 bin/haml-i18n-extractor
  2. +26 −1 lib/haml-i18n-extractor/cli.rb
View
20 bin/haml-i18n-extractor
@@ -4,23 +4,9 @@ require 'haml-i18n-extractor'
@prompter = Haml::I18n::Extractor::Prompter.new
-option_parser = Trollop::Parser.new do
- banner <<-EOB
-
- haml-i18n-extractor <path> [--interactive|--non-interactive] [--other-options]
-
- See options list:
-EOB
- version "Current version: #{Haml::I18n::Extractor::VERSION}"
- opt :interactive, "interactive mode", :short => 'i'
- opt :non_interactive, "non interactive mode", :short => 'n'
- opt :yaml_file, "yaml file path, defaults to config/locales/en.yml", :type => String, :short => 'y'
- opt :i18n_scope, "top level i18n scope, defaults to :en", :type => String, :short => 's'
-end
-
-opts = Trollop::with_standard_exception_handling option_parser do
+opts = Trollop::with_standard_exception_handling Haml::I18n::Extractor::CLI.option_parser do
raise Trollop::HelpNeeded if ARGV.empty?
- option_parser.parse ARGV
+ Haml::I18n::Extractor::CLI.option_parser.parse ARGV
end
path_to_extract = File.expand_path(ARGV[0])
@@ -31,5 +17,5 @@ end
begin
Haml::I18n::Extractor::CLI.new(opts).start
rescue Haml::I18n::Extractor::CLI::CliError
- @prompter.puts("please try again")
+ Haml::I18n::Extractor::CLI.show_help!
end
View
27 lib/haml-i18n-extractor/cli.rb
@@ -8,6 +8,31 @@ def initialize(opts)
@prompter = Haml::I18n::Extractor::Prompter.new # may as well
end
+ def self.option_parser
+ option_parser = Trollop::Parser.new do
+ banner <<-EOB
+
+ haml-i18n-extractor --version # print version of this gem
+ haml-i18n-extractor --help # this message
+ haml-i18n-extractor <path> [--interactive|--non-interactive] [--other-options]
+
+ See options list (short options available next to long option):\n
+
+ EOB
+ version "Current version: #{Haml::I18n::Extractor::VERSION}"
+ opt :interactive, "interactive mode", :short => 'i'
+ opt :non_interactive, "non interactive mode", :short => 'n'
+ opt :yaml_file, "yaml file path, defaults to config/locales/en.yml", :type => String, :short => 'y'
+ opt :i18n_scope, "top level i18n scope, defaults to :en", :type => String, :short => 's'
+ end
+ end
+
+ def self.show_help!
+ Trollop::with_standard_exception_handling option_parser do
+ raise Trollop::HelpNeeded
+ end
+ end
+
def start
check_interactive_or_not_passed
if @options[:path]
@@ -30,7 +55,7 @@ def start
def check_interactive_or_not_passed
if (!@options[:interactive] && !@options[:non_interactive]) || (@options[:interactive] && @options[:non_interactive])
@prompter.puts("You must choose either one of interactive mode or non interactive mode.")
- @prompter.puts("See haml-i18n-extractor --help")
+ @prompter.puts("See haml-i18n-extractor --help below:")
raise CliError
end
end

0 comments on commit 5bb237a

Please sign in to comment.
Something went wrong with that request. Please try again.