Futilities/v0.6/clade/Sys/Opts/@code/2026/05/24

From WoozleCodes
Jump to navigation Jump to search
2026/05/23 2026/05/24 2026/05/25

Is this still in use?

#
    private $arAppOpts = []; // TODO 2026-04-28: make these an OArray
    protected function GetAppOptions() : array { return $this->arAppOpts; }
    protected function AddAppOption(string $sKey, string $sText) {
        $this->arAppOpts[strtolower($sText)] = $sKey;
    }
    // $ar is [code name => [array of CLI strings which indicate that option]]
    protected function AddAppOptions(array $ar) {
        foreach ($ar as $sKey => $arText) {
            foreach ($arText as $sText) {
                $this->AddAppOption($sKey,$sText);
            }
        }
    }

Is this still in use?

  • PURPOSE: checks to see if the option-index includes the given option
  • INPUT:
    • $sText = full option parameter, possibly including value (demarcated by ':' or '=')
  • HISTORY:
#
    protected function HasAppOption(string $sText) : bool {
        if ($sText != '') {
            // check for value demarcator (':' or '=')
            $npMark = strcspn($sText,':=');
            if ($npMark > 0) {
                // get just the option name
                $sOptName = substr($sText,0,$npMark);
                $isFnd = array_key_exists(strtolower($sOptName),$this->arAppOpts);
                return $isFnd;
            }
            throw new \exception("2022-09-30 shouldn't we be checking \$sText here?");
        }
        return FALSE;
    }
    protected function GetAppOptionKey(string $sText) : string { return $this->arAppOpts[$sText]; }

Are these still in use?

  • HISTORY:
    • 2022-10-20 Improving this a bit so it groups all option aliases together
      • TODO: make it possible for each option to have a brief description as well
#
    protected function ListAppOptions(string $sPfx = '  ', bool $isDebug = FALSE) : ?string {
        $arExt = $this->GetAppOptions();    // array of external codes
        $out = NULL;
        ksort($arExt);
        // build array of internal codes
        foreach ($arExt as $sExt => $sText) {
            #$out .= "$sPfx($sText) $sKey\n";
            $arInt[$sText][] = $sExt;
        }
        foreach ($arInt as $sInt => $arExt) {
            $sIntShow = ($isDebug ? " ($sInt):" : '');
            $out .= $sPfx.$sIntShow;
            foreach ($arExt as $sExt) {
                $out .= ' '.$sExt;
            }
            $out .= "\n";
        }
        return $out;
    }
    protected function ShowAppOptions() : string {
        $sOpt = $this->ListAppOptions();
        if (is_null($sOpt)) {
            $out = "(no options available)\n";
        } else {
            $out = "Options: \n".$this->ListAppOptions();
        }
        return $out;
    }