[logaling-commit] logaling/logaling-command [master] Add --no-pager option

Back to archive index

null+****@clear***** null+****@clear*****
Tue Feb 14 17:16:59 JST 2012


SHIMADA Koji	2012-02-14 17:16:59 +0900 (Tue, 14 Feb 2012)

  New Revision: 4532af0b1340f9a38c2f493e9a04a31bfb7ceead

  Merged 6e3a81f: Merge pull request #42 from logaling/add-no-pager

  Log:
    Add --no-pager option

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

  Modified: lib/logaling/command/application.rb (+6 -3)
===================================================================
--- lib/logaling/command/application.rb    2012-02-13 16:40:35 +0900 (1dbf4e4)
+++ lib/logaling/command/application.rb    2012-02-14 17:16:59 +0900 (a94e0a6)
@@ -171,13 +171,14 @@ module Logaling::Command
 
     desc 'lookup [TERM]', 'Lookup terms.'
     method_option "output", type: :string, default: "terminal"
+    method_option "no-pager", type: :boolean, default: false
     def lookup(source_term)
       @repository.index
       terms =****@repos*****(source_term, @source_language, @target_language,
                                 @config["glossary"])
       unless terms.empty?
         max_str_size = terms.map{|term| term[:source_term].size}.sort.last
-        run_pager
+        run_pager unless options["no-pager"]
         terms.each_with_index do |term, i|
           source_string = extract_source_string_and_coloring(term)
           target_string = term[:target_term].bright
@@ -205,6 +206,7 @@ module Logaling::Command
     end
 
     desc 'show', 'Show terms in glossary.'
+    method_option "no-pager", type: :boolean, default: false
     def show
       required_options = {
         "glossary" => "input glossary name '-g <glossary name>'",
@@ -215,7 +217,7 @@ module Logaling::Command
       @repository.index
       terms =****@repos*****_glossary(@config["glossary"], @config["source-language"], @config["target-language"])
       unless terms.empty?
-        run_pager
+        run_pager unless options["no-pager"]
         max_str_size = terms.map{|term| term[:source_term].size}.sort.last
         terms.each do |term|
           target_string = "#{term[:target_term]}"
@@ -231,11 +233,12 @@ module Logaling::Command
     end
 
     desc 'list', 'Show glossary list.'
+    method_option "no-pager", type: :boolean, default: false
     def list
       @repository.index
       glossaries =****@repos*****
       unless glossaries.empty?
-        run_pager
+        run_pager unless options["no-pager"]
         glossaries.each do |glossary|
           printf("  %s\n", glossary)
         end

  Modified: spec/logaling/command_spec.rb (+8 -10)
===================================================================
--- spec/logaling/command_spec.rb    2012-02-13 16:40:35 +0900 (510208c)
+++ spec/logaling/command_spec.rb    2012-02-14 17:16:59 +0900 (51c023d)
@@ -23,7 +23,6 @@ describe Logaling::Command::Application do
   let(:glossary_path) { Logaling::Glossary.build_path('spec', 'en', 'ja') }
   let(:target_project_path) { File.join(LOGALING_HOME, "projects", "spec") }
   let(:repository) { Logaling::Repository.new(LOGALING_HOME) }
-  let(:stop_pager) { STDOUT.stub!(:tty?).and_return(false) }
 
   before do
     FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
@@ -273,7 +272,7 @@ describe Logaling::Command::Application do
       context 'but global config have it' do
         before do
           command.add('test-logaling', '設定ファイルのテスト')
-          stop_pager
+          command.options = base_options.merge("no-pager" => true)
           @stdout = capture(:stdout) {command.lookup("test-logaling")}
         end
 
@@ -330,8 +329,7 @@ describe Logaling::Command::Application do
 
   describe '#lookup' do
     before do
-      stop_pager
-      command.options = base_options.merge("output" => "terminal")
+      command.options = base_options.merge("output" => "terminal", "no-pager" => true)
       command.new('spec', 'en', 'ja')
       command.add("spec", "スペック", "備考")
     end
@@ -360,7 +358,7 @@ describe Logaling::Command::Application do
     context 'with arguments exist term' do
       before do
         command.delete('spec', 'スペックろがりん')
-        stop_pager
+        command.options = base_options.merge("no-pager" => true)
         @stdout = capture(:stdout) {command.lookup("spec")}
       end
 
@@ -373,7 +371,7 @@ describe Logaling::Command::Application do
       context 'only 1 bilingual pair exist' do
         before do
           command.delete('spec')
-          stop_pager
+          command.options = base_options.merge("no-pager" => true)
           @stdout = capture(:stdout) {command.lookup("spec")}
         end
 
@@ -404,7 +402,7 @@ describe Logaling::Command::Application do
             command.add('term', '用語1', '備考')
             command.add('term', '用語2', '備考')
             command.delete("term")
-            stop_pager
+            command.options = base_options.merge("no-pager" => true)
             @stdout = capture(:stdout) {command.lookup("term")}
           end
 
@@ -430,7 +428,7 @@ describe Logaling::Command::Application do
 
     context 'when .logaling exists' do
       before do
-        stop_pager
+        command.options = base_options.merge("no-pager" => true)
         @stdout = capture(:stdout) {command.show}
       end
 
@@ -453,7 +451,7 @@ describe Logaling::Command::Application do
 
     context 'when some glossaries are registered' do
       before do
-        stop_pager
+        command.options = base_options.merge("no-pager" => true)
         @stdout = capture(:stdout) {command.list}
       end
 
@@ -465,7 +463,7 @@ describe Logaling::Command::Application do
     context 'when a glossary is unregistered' do
       before do
         repository.unregister('spec')
-        stop_pager
+        command.options = base_options.merge("no-pager" => true)
         @stdout = capture(:stdout) {command.list}
       end
 




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