Sub-Term Mapping Tools

CmdLine with Argument Options

I. Description

This class extends the CmdLine (basic) class to provide basic function of interactive interface for command line tool and read information from command line arguments. This class provides following default argument options:
  • -h: Show program help menu (this is it)
  • -hs: Show hierarchy structure of all options
  • -p: Show prompt

The following steps are needed to use this class:

  • make YourClass as a sub-class of CmdLineArgs
    import gov.nih.nlm.nls.stmt.CmdLine.*;
    import gov.nih.nlm.nls.stmt.Lib.*;
    import gov.nih.nlm.nls.lvg.CmdLineSyntax.*;
    public class YourClass extends CmdLineArgs
  • instantiate YourClass and call Run(args) method in the main method
    YourClass yourClass = new YourClass();
    yourClass.Run(args);
  • override following methods
    • protected void InitLocalObjs()
      => instantiate local data members
    • protected void SetToolInfo()
      => set tool info, such as promptStr, tool name, version, config file, etc.
    • protected void CloseLocalObjs()
      => clean up local data members
    • protected void ProcessLine(String line)
      => how to process the input line

    • protected String SetLocalFlagStr()
      => Set argument option flag strings of YourClass
    • protected void SetLocalOptions()
      => Set full name of option flags and help menu of YourClass
    • protected void ExecuteLocalOption(OptionItem nameItem)
      => Set data members based on option flags of YourClass
    • protected void SetLocalDefaultOption()
      => Set data members of YourClass (not based on option flags)

II. Main Algorithm


public void Run(String[] args)
=> Same as CmdLine

protected boolean PreProcess(String[] args)

  • PreProcess: init data members
  • Override protected method:
    • SetToolInfo( );
      => protected method and must be override in YourClass
    • SetOptionFlags( );
      => define cmd line tool systemOption_
      • define all standard system arguments flags, full name, and help menu
      • SetLocalFlagStr( );
        => protected method and must be override in YourClass
      • SetLocalOptions( );
        => protected method and must be override in YourClass
    • String optionStr = GetOptionStr(args);
      => get option str form input args
    • option_ = new Option(optionStr);
      => instantiate input options from option str
    • check legal arguments option, if true
      • SetValues( );
        • SetValuesByDefault( );
          => Set default promptStr based onplatform
        • SetValuesByCmdLineOptions( );
          • ExecuteOptions( );
            • Set standard data member based on arguments
            • ExecuteLocalOption(nameItem);
              => protected method and must be override in YourClass
          • SetLocalDefaultOption( );
            => protected method and must be override in YourClass
      • If (runFlag_ == true)
        • InitLocalObjs( );
          => protected method and must be override in YourClass

protected void Process()
=> Same as CmdLine

protected void PostProcess()
=> Same as CmdLine

protected void HelpMenu()

  • Print out help menu
  • Override protected method

III. Abstract Methods

  • protected void InitLocalObjs()
    => instantiate local data members
  • protected void SetToolInfo()
    => set tool info, such as promptStr, tool name, version, config file, etc.
  • protected void CloseLocalObjs()
    => clean up local data members
  • protected void ProcessLine(String line)
    => how to process the input line

  • protected String SetLocalFlagStr()
    => Set argument option flag strings of YourClass
  • protected void SetLocalOptions()
    => Set full name of option flags and help menu of YourClass
  • protected void ExecuteLocalOption(OptionItem nameItem)
    => Set data members based on option flags of YourClass
  • protected void SetLocalDefaultOption()
    => Set data members of YourClass (not based on option flags)