class TaskJuggler::Tj3Man

Public Class Methods

new() click to toggle source
Calls superclass method TaskJuggler::Tj3AppBase.new
# File lib/taskjuggler/apps/Tj3Man.rb, line 24
def initialize
  super

  @man = SyntaxReference.new
  @keywords = TernarySearchTree.new(@man.all)
  @manual = false
  @showHtml = false
  @browser = ENV['BROWSER'] || 'firefox'
  @directory = nil
  @mininumRubyVersion = '1.8.7'
end

Public Instance Methods

appMain(requestedKeywords) click to toggle source
# File lib/taskjuggler/apps/Tj3Man.rb, line 65
def appMain(requestedKeywords)
  if @manual
    UserManual.new.generate(@directory)
  elsif requestedKeywords.empty?
    showManual
  else
    requestedKeywords.each do |keyword|
      if (kws = @keywords[keyword, true]).nil?
        error('tj3man_no_matches', "No matches found for '#{keyword}'")
      elsif kws.length == 1 || kws.include?(keyword)
        showManual(keyword)
      else
        warning('tj3man_multi_match',
                "Multiple matches found for '#{keyword}':\n" +
                "#{kws.join(', ')}")
      end
    end
  end

  0
end
processArguments(argv) click to toggle source
# File lib/taskjuggler/apps/Tj3Man.rb, line 36
    def processArguments(argv)
      super do
        @opts.banner += <<'EOT'
This program can be used to generate the user manual in HTML format or to get
a textual help for individual keywords.
EOT
        @opts.on('-d', '--dir <directory>', String,
                format('directory to put the manual')) do |dir|
          @directory = dir
        end
        @opts.on('--html',
                 format('Show the user manual in your local web browser. ' +
                        'By default, Firefox is used or the brower specified ' +
                        'with the $BROWSER environment variable.')) do
          @showHtml = true
        end
        @opts.on('--browser <command>', String,
                 format('Specify the command to start your web browser. ' +
                        'The default is \firefox\.')) do |browser|
          @browser = browser
        end
        @opts.on('-m', '--manual',
                format('Generate the user manual into the current directory ' +
                       'or the directory specified with the -d option.')) do
          @manual = true
        end
      end
    end

Private Instance Methods

showManual(keyword = nil) click to toggle source
# File lib/taskjuggler/apps/Tj3Man.rb, line 89
def showManual(keyword = nil)
  if @showHtml
    # If the user requested HTML format, we start the browser.
    startBrowser(keyword)
  else
    if keyword
      # Print the documentation for the keyword.
      puts @man.to_s(keyword)
    else
      # Print a list of all documented keywords.
      puts @man.all.join("\n")
    end
  end
end
startBrowser(keyword = nil) click to toggle source

Start the web browser with either the entry page or the page for the specified keyword.

# File lib/taskjuggler/apps/Tj3Man.rb, line 106
def startBrowser(keyword = nil)
  # Find the manual relative to this file.
  manualDir = File.join(File.dirname(__FILE__), '..', '..', '..',
                        'manual', 'html')
  file = "#{manualDir}/#{keyword || 'index'}.html"
  # Make sure the file exists.
  unless File.exists?(file)
    $stderr.puts "Cannot open manual file #{file}"
    exit 1
  end

  # Start the browser.
  begin
    %x#{@browser} file:#{file}`
  rescue
    $stderr.puts "Cannot open browser: #{$!}"
    exit 1
  end
end