/** * Returns the "Help Text" based on the way this QCliParameterProcessor is set up. * @return string */ public function GetHelpText() { $strToReturn = $this->strHelpTextHeadline . "\r\n"; $strToReturn .= 'usage: qcodo ' . $this->strQcodoCliCommand . ' '; if (count($this->mixValueArray)) { $strToReturn .= '[OPTIONS] '; } if (count($this->strDefaultIdentifierArray)) { $strToReturn .= implode(' ', $this->strDefaultIdentifierArray); } $strToReturn .= "\r\n\r\n"; // Default Identifier MaxLength and associated HelpText width and padding $intMaxIdentifierLength = 16; $strPadding = str_repeat(' ', $intMaxIdentifierLength + 4); $intHelpTextWidth = 78 - $intMaxIdentifierLength - 4; // Printout any required parameters if (count($this->strDefaultIdentifierArray)) { $strToReturn .= "required parameters:\r\n"; // Update MaxIdLength calculation (if applicable) foreach ($this->strDefaultIdentifierArray as $strDefaultIdentifier) { if (strlen($strDefaultIdentifier) > $intMaxIdentifierLength) { $intMaxIdentifierLength = strlen($strDefaultIdentifier); } } $strPadding = str_repeat(' ', $intMaxIdentifierLength + 4); $intHelpTextWidth = 78 - $intMaxIdentifierLength - 4; // Render the Required Parameters foreach ($this->strDefaultIdentifierArray as $intIndex => $strDefaultIdentifier) { $strToReturn .= sprintf(" %-" . $intMaxIdentifierLength . "s %s\r\n", $strDefaultIdentifier, QCliParameterProcessor::RenderHelpText($this->strDefaultHelpTextArray[$intIndex], $intHelpTextWidth, $strPadding)); } $strToReturn .= "\r\n"; } // Printout any optional parameters if (count($this->mixValueArray)) { $strToReturn .= "optional parameters:\r\n"; foreach ($this->mixValueArray as $intIndex => $mixValue) { // First, figure out the formal label for the "identifier" $strIdentifier = ''; if (array_key_exists($intIndex, $this->chrShortIdentifierByIndex)) { $strIdentifier .= '-' . $this->chrShortIdentifierByIndex[$intIndex]; } if (array_key_exists($intIndex, $this->strLongIdentifierByIndex)) { if ($strIdentifier) { $strIdentifier .= ', '; } $strIdentifier .= '--' . $this->strLongIdentifierByIndex[$intIndex]; } // For non-flags (actual named parameters) output the parameter type we are expecting if (array_key_exists($intIndex, $this->intParameterTypeArray)) { $strIdentifier .= '=' . QCliParameterType::$NameArray[$this->intParameterTypeArray[$intIndex]]; } // Print it out by itself, or include the help text (if applicable) if (!($strHelpText = $this->strHelpTextArray[$intIndex])) { $strToReturn .= ' ' . $strIdentifier . "\r\n"; } else { $strHelpText = QCliParameterProcessor::RenderHelpText($strHelpText, $intHelpTextWidth, $strPadding); if (strlen($strIdentifier) > $intMaxIdentifierLength) { $strToReturn .= sprintf(" %s\r\n%s%s\r\n", $strIdentifier, $strPadding, $strHelpText); } else { $strToReturn .= sprintf(" %-" . $intMaxIdentifierLength . "s %s\r\n", $strIdentifier, $strHelpText); } } } $strToReturn .= "\r\n"; } // Return the rendered Help Text return $strToReturn; }