lib/ctioga2/commands/doc/help.rb in ctioga2-0.6.1 vs lib/ctioga2/commands/doc/help.rb in ctioga2-0.7
- old
+ new
@@ -16,11 +16,11 @@
require 'ctioga2/commands/parsers/command-line'
require 'ctioga2/commands/doc/wordwrap'
module CTioga2
- Version::register_svn_info('$Revision: 409 $', '$Date: 2013-08-22 21:23:51 +0200 (Thu, 22 Aug 2013) $')
+ Version::register_svn_info('$Revision: 532 $', '$Date: 2013-09-29 12:13:33 +0200 (Sun, 29 Sep 2013) $')
module Commands
module Documentation
@@ -97,18 +97,28 @@
# Disable color output if not a to a terminal
if ! @to_tty
@color = false
end
+ should_close = false
+ output = $stdout
+
if @to_tty and @to_pager
# We pass -R as default value...
ENV['LESS'] = 'R'
- output = IO::popen("pager", "w")
- pager = true
- else
- output = $stdout
- pager = false
+ pager = 'pager'
+ for w in [ENV['PAGER'], 'less', 'pager' ]
+ if Utils::which(w)
+ pager = w
+ break
+ end
+ end
+ begin
+ output = IO::popen(pager, "w")
+ should_close = true
+ rescue
+ end
end
for group in groups
output.puts unless group == groups[0]
name = (group && group.name) || "Ungrouped commands"
@@ -121,10 +131,10 @@
}
output.puts format_one_entry(cmd)
end
end
- output.close
+ output.close if should_close
end
protected
# Formats one entry of the commands