[logaling-commit] logaling/logaling-command [fix-loga-config] put error message if logaling-home not available

Back to archive index

null+****@clear***** null+****@clear*****
Mon Feb 27 18:22:06 JST 2012


SUZUKI Miho	2012-02-27 18:22:06 +0900 (Mon, 27 Feb 2012)

  New Revision: 309872ca796426a2e3cd2c757641405a6a2b8070

  Log:
    put error message if logaling-home not available

  Modified files:
    lib/logaling/command/application.rb

  Modified: lib/logaling/command/application.rb (+19 -1)
===================================================================
--- lib/logaling/command/application.rb    2012-02-27 11:25:37 +0900 (0d3400e)
+++ lib/logaling/command/application.rb    2012-02-27 18:22:06 +0900 (f72879f)
@@ -79,6 +79,7 @@ module Logaling::Command
     desc 'import', 'Import external glossary'
     method_option "list", type: :boolean, default: false
     def import(external_glossary=nil)
+      check_logaling_home_exists
       require "logaling/external_glossary"
       Logaling::ExternalGlossary.load
       if options["list"]
@@ -87,6 +88,8 @@ module Logaling::Command
         @repository.import(Logaling::ExternalGlossary.get(external_glossary))
         @repository.index
       end
+    rescue Logaling::CommandFailed => e
+      say e.message
     rescue Logaling::ExternalGlossaryNotFound
       say "'#{external_glossary}' can't find in import list."
       say "Try 'loga import --list' and confirm import list."
@@ -96,6 +99,7 @@ module Logaling::Command
     def register
       @config.check_required_option("glossary" => "input glossary name '-g <glossary name>'")
       raise Logaling::CommandFailed, "Try 'loga new' first." unless File.exist?(@dotfile_path)
+      check_logaling_home_exists
 
       @repository.register(@dotfile_path, @config.glossary)
       @repository.index
@@ -123,7 +127,9 @@ module Logaling::Command
    method_option "global", type: :boolean, default: false
    def config(key, value)
      if options["global"]
-       FileUtils.mkdir_p(@logaling_home) unless File.exist?(@logaling_home)
+       unless File.exist?(@logaling_home)
+         FileUtils.mkdir_p(@logaling_home) rescue raise Logaling::CommandFailed, "Imput existing directory as logaling-home."
+       end
        config_path = File.join(@logaling_home, "config")
      else
        raise Logaling::CommandFailed, "Can't found .logaling" unless @project_config_path
@@ -145,6 +151,7 @@ module Logaling::Command
         "target-language" => "input target-language code '-T <target-language code>'"
       }
       @config.check_required_option(required_options)
+      check_logaling_home_exists
       @repository.index
 
       if****@repos*****_pair_exists?(source_term, target_term, @config.glossary)
@@ -165,6 +172,7 @@ module Logaling::Command
         "target-language" => "input target-language code '-T <target-language code>'"
       }
       @config.check_required_option(required_options)
+      check_logaling_home_exists
 
       if target_term
         glossary.delete(source_term, target_term)
@@ -185,6 +193,7 @@ module Logaling::Command
         "target-language" => "input target-language code '-T <target-language code>'"
       }
       @config.check_required_option(required_options)
+      check_logaling_home_exists
       @repository.index
 
       if****@repos*****_pair_exists_and_has_same_note?(source_term, new_target_term, note, @config.glossary)
@@ -203,6 +212,7 @@ module Logaling::Command
     method_option "no-pager", type: :boolean, default: false
     method_option "dictionary", type: :boolean, default: false, aliases: "--dict"
     def lookup(source_term)
+      check_logaling_home_exists
       @repository.index
       terms =****@repos*****(source_term, glossary, options["dictionary"])
       unless terms.empty?
@@ -243,6 +253,7 @@ module Logaling::Command
         "target-language" => "input target-language code '-T <target-language code>'"
       }
       @config.check_required_option(required_options)
+      check_logaling_home_exists
       @repository.index
       terms =****@repos*****_glossary(@glossary)
       unless terms.empty?
@@ -264,6 +275,7 @@ module Logaling::Command
     desc 'list', 'Show glossary list.'
     method_option "no-pager", type: :boolean, default: false
     def list
+      check_logaling_home_exists
       @repository.index
       glossaries =****@repos*****
       unless glossaries.empty?
@@ -353,6 +365,12 @@ module Logaling::Command
       display_string
     end
 
+    def check_logaling_home_exists
+      unless File.exist?(@logaling_home)
+        raise Logaling::CommandFailed, "Imput existing directory as logaling-home."
+      end
+    end
+
     def printer(source_string, target_string, note=nil,
                 glossary_name, max_str_size, i, last)
       case options["output"]




More information about the logaling-commit mailing list
Back to archive index