#!/usr/bin/php
<?PHP
/** @brief
 *  @version 0.0
 *  @author Teodor Väänänen
 *  @copyright © 2021 by MT Invictus.
 *  @date 2021-12-07: Created by Teodor Väänänen.
 */

if ( \php_sapi_name() !== 'cli' )
  die('This tool is for command-line use only') ;

$linkFarm = (object)[
   'actions' => (object)[
    'address-book-new' => false,
    'application-exit' => false,
    'appointment-new' => false,
    'call-start' => false,
    'call-stop' => false,
    'contact-new' => false,
    'document-new' => false,
    'document-open' => false,
    'document-open-recent' => false,
    'document-page-setup' => false,
    'document-print' => 'stock/solid/print',
    'document-print-preview' => false,
    'document-properties' => false,
    'document-revert' => false,
    'document-save' => 'stock/solid/save',
    'document-save-as' => false,
    'document-send' => false,
    'edit-clear' => false,
    'edit-copy' => 'stock/solid/copy',
    'edit-cut' => 'stock/solid/cut',
    'edit-delete' => 'stock/solid/times',
    'edit-find' => 'stock/solid/binoculars',
    'edit-find-replace' => false,
    'edit-paste' => 'stock/solid/paste',
    'edit-redo' => 'stock/solid/redo',
    'edit-select-all' => false,
    'edit-undo' => 'stock/solid/undo',
    'folder-new' => 'stock/solid/folder-plus',
    'format-indent-less' => 'stock/solid/outdent',
    'format-indent-more' => 'stock/solid/indent',
    'format-justify-center' => 'stock/solid/align-center',
    'format-justify-fill' => 'stock/solid/align-justify',
    'format-justify-left' => 'stock/solid/align-left',
    'format-justify-right' => 'stock/solid/align-right',
    'format-list-ordered' => 'stock/solid/list-ol',
    'format-list-unordered' => 'stock/solid/list-ul',
    'format-text-bold' => 'stock/solid/bold',
    'format-text-direction-ltr' => false,
    'format-text-direction-rtl' => false,
    'format-text-italic' => 'stock/solid/italic',
    'format-text-strikethrough' => 'stock/solid/strikethrough',
    'format-text-subscript' => 'stock/solid/subscript',
    'format-text-superscript' => 'stock/solid/superscript',
    'format-text-underline' => 'stock/solid/underline',
    'go-bottom' => false,
    'go-down' => false,
    'go-first' => false,
    'go-home' => false,
    'go-jump' => false,
    'go-last' => false,
    'go-next' => false,
    'go-previous' => false,
    'go-top' => false,
    'go-up' => false,
    'help-about' => false,
    'help-contents' => false,
    'help-faq' => false,
    'insert-image' => false,
    'insert-link' => false,
    'insert-object' => false,
    'insert-text' => false,
    'list-add' => false,
    'list-remove' => false,
    'mail-forward' => false,
    'mail-mark-important' => false,
    'mail-mark-junk' => false,
    'mail-mark-notjunk' => false,
    'mail-mark-read' => false,
    'mail-mark-unread' => false,
    'mail-message-new' => false,
    'mail-reply-all' => false,
    'mail-reply-sender' => false,
    'mail-send' => false,
    'mail-send-receive' => false,
    'media-eject' => false,
    'media-playback-pause' => false,
    'media-playback-start' => false,
    'media-playback-stop' => false,
    'media-record' => false,
    'media-seek-backward' => false,
    'media-seek-forward' => false,
    'media-skip-backward' => false,
    'media-skip-forward' => false,
    'object-flip-horizontal' => false,
    'object-flip-vertical' => false,
    'object-rotate-left' => false,
    'object-rotate-right' => false,
    'process-stop' => false,
    'system-lock-screen' => false,
    'system-log-out' => false,
    'system-reboot' => false,
    'system-run' => false,
    'system-search' => false,
    'system-shutdown' => false,
    'tools-check-spelling' => false,
    'view-fullscreen' => false,
    'view-refresh' => false,
    'view-restore' => false,
    'view-sort-ascending' => false,
    'view-sort-descending' => false,
    'window-close' => false,
    'window-new' => false,
    'zoom-fit-best' => false,
    'zoom-in' => false,
    'zoom-original' => false,
    'zoom-out' => false,
  ],
  'animations' => (object)[
    'process-working' => false,
  ],
  'applets' => (object)[
  ],
  'apps' => (object)[
    'accessories-calculator' => false,
    'accessories-character-map' => false,
    'accessories-dictionary' => false,
    'accessories-text-editor' => false,
    'help-browser' => false,
    'multimedia-volume-control' => false,
    'preferences-desktop-accessibility' => false,
    'preferences-desktop-font' => false,
    'preferences-desktop-keyboard' => false,
    'preferences-desktop-locale' => false,
    'preferences-desktop-multimedia' => false,
    'preferences-desktop-screensaver' => false,
    'preferences-desktop-theme' => false,
    'preferences-desktop-wallpaper' => false,
    'system-file-manager' => false,
    'system-software-install' => false,
    'system-software-update' => false,
    'utilities-system-monitor' => false,
    'utilities-terminal' => false,
  ],
   'categories' => (object)[
    'applications-accessories' => false,
    'applications-development' => false,
    'applications-engineering' => false,
    'applications-games' => false,
    'applications-graphics' => false,
    'applications-internet' => false,
    'applications-multimedia' => false,
    'applications-office' => false,
    'applications-other' => false,
    'applications-science' => false,
    'applications-system' => false,
    'applications-utilities' => false,
    'preferences-desktop' => false,
    'preferences-desktop-peripherals' => false,
    'preferences-desktop-personal' => false,
    'preferences-other' => false,
    'preferences-system' => false,
    'preferences-system-network' => false,
    'system-help' => false,
  ],
  'devices' => (object)[
    'audio-card' => false,
    'audio-input-microphone' => false,
    'battery' => false,
    'camera-photo' => false,
    'camera-video' => false,
    'camera-web' => false,
    'computer' => false,
    'drive-harddisk' => false,
    'drive-optical' => false,
    'drive-removable-media' => false,
    'input-gaming' => false,
    'input-keyboard' => false,
    'input-mouse' => false,
    'input-tablet' => false,
    'media-flash' => false,
    'media-floppy' => false,
    'media-optical' => false,
    'media-tape' => false,
    'modem' => false,
    'multimedia-player' => false,
    'network-wired' => false,
    'network-wireless' => false,
    'pda' => false,
    'phone' => false,
    'printer' => false,
    'scanner' => false,
    'video-display' => false,
  ],
  'emblems' => (object)[
    'emblem-default' => false,
    'emblem-documents' => false,
    'emblem-downloads' => false,
    'emblem-favorite' => false,
    'emblem-important' => false,
    'emblem-mail' => false,
    'emblem-photos' => false,
    'emblem-readonly' => false,
    'emblem-shared' => false,
    'emblem-symbolic-link' => false,
    'emblem-synchronized' => false,
    'emblem-system' => false,
    'emblem-unreadable' => false,
  ],
  'emotes' => (object)[
    'face-angel' => false,
    'face-angry' => 'stock/solid/angry',
    'face-cool' => false,
    'face-crying' => false,
    'face-devilish' => false,
    'face-embarrassed' => false,
    'face-kiss' => false,
    'face-laugh' => 'stock/solid/laugh',
    'face-monkey' => false,
    'face-plain' => false,
    'face-raspberry' => false,
    'face-sad' => false,
    'face-sick' => false,
    'face-smile' => false,
    'face-smile-big' => false,
    'face-smirk' => false,
    'face-surprise' => false,
    'face-tired' => false,
    'face-uncertain' => false,
    'face-wink' => false,
    'face-worried' => false,
  ],
  'intl' => (object)[
  ],
  'logo' => 'stock/regular/font-awesome-logo-full',
  'mimetypes' => (object)[
    'application-pdf' => 'stock/solid/file-pdf',
    'application-x-executable' => false,
    'audio-x-generic' => 'stock/solid/file-audio',
    'font-x-generic' => false,
    'image-x-generic' => 'stock/solid/file-image',
    'inode-directory' => false,
    'package-x-generic' => false,
    'text-html' => false,
    'text-x-generic' => false,
    'text-x-generic-template' => false,
    'text-x-script' => false,
    'video-x-generic' => 'stock/solid/file-video',
    'x-office-address-book' => false,
    'x-office-calendar' => false,
    'x-office-document' => false,
    'x-office-presentation' => false,
    'x-office-spreadsheet' => false,
  ],
  'places' => (object)[
    'folder-remote' => false,
    'network-server' => false,
    'network-workgroup' => false,
    'older' => false,
    'start-here' => false,
    'user-bookmarks' => false,
    'user-desktop' => false,
    'user-home' => false,
    'user-trash' => false,
  ],
  'status' => (object)[
    'appointment-missed' => false,
    'appointment-soon' => false,
    'audio-volume-high' => false,
    'audio-volume-low' => false,
    'audio-volume-medium' => false,
    'audio-volume-muted' => false,
    'battery-caution' => false,
    'battery-low' => false,
    'dialog-error' => false,
    'dialog-information' => false,
    'dialog-password' => false,
    'dialog-question' => false,
    'dialog-warning' => false,
    'folder-drag-accept' => false,
    'folder-open' => false,
    'folder-visiting' => false,
    'image-loading' => false,
    'image-missing' => false,
    'mail-attachment' => false,
    'mail-read' => false,
    'mail-replied' => false,
    'mail-signed' => false,
    'mail-signed-verified' => false,
    'mail-unread' => false,
    'media-playlist-repeat' => false,
    'media-playlist-shuffle' => false,
    'network-error' => false,
    'network-idle' => false,
    'network-offline' => false,
    'network-receive' => false,
    'network-transmit' => false,
    'network-transmit-receive' => false,
    'printer-error' => false,
    'printer-printing' => false,
    'security-high' => false,
    'security-low' => false,
    'security-medium' => false,
    'software-update-available' => false,
    'software-update-urgent' => false,
    'sync-error' => false,
    'sync-synchronizing' => false,
    'task-due' => false,
    'task-past-due' => false,
    'user-available' => false,
    'user-away' => false,
    'user-idle' => false,
    'user-offline' => false,
    'user-trash-full' => false,
    'weather-clear' => false,
    'weather-clear-night' => false,
    'weather-few-clouds' => false,
    'weather-few-clouds-night' => false,
    'weather-fog' => false,
    'weather-overcast' => false,
    'weather-severe-alert' => false,
    'weather-showers' => false,
    'weather-showers-scattered' => false,
    'weather-snow' => false,
    'weather-storm' => false,
  ],
  'title' => 'Fontawesome Symbolic Links',
  'version' => '5.12.1',
] ;

$options = [
  'h' => [ "help", "", "This text." ],
  'c::' => [ 'color', '#rrggbb', 'Set color.'],
  'd:' => [ 'destination', 'dest', 'Output to directory <dest>.'],
] ;

$shortopts = "" ;
$longopts = [] ;

/* Construct the longops and shortopts arrays args to getopt()
 */
foreach ( $options as $k => $v )
  $longopts[] = $v[0] . substr($k, 1) ;

$shortopts = \implode('', \array_keys($options)) ;

function Usage()
{
  global $options ;
  $name = \pathinfo($_SERVER['argv'][0], PATHINFO_FILENAME) ;
  $w = [] ;
  echo "Usage:" . PHP_EOL ;

  foreach ( $options as $k => $v ) {

    echo "  -{$k[0]}" ;

    if ( !empty($k[1]) && $k[1] == ':' ) {
      if ( !empty($k[2]) && $k[2] == ':' ) {
        echo "[<{$v[1]}>]" ;
      }
      else {
        echo "<{$v[1]}>" ;

      }
    }
    if ( !empty($v[0]) ) {
      echo ", --{$v[0]}" ;
      if ( !empty($k[1]) && $k[1] == ':' ) {
        if ( !empty($k[2]) && $k[2] == ':' ) {
          echo "[=<{$v[1]}>]" ;
        }
        else {
          echo " <{$v[1]}>" ;
        }
      }
    }
    echo PHP_EOL . '    ' . $v[2] . PHP_EOL ;
  }

}

$go = \getopt($shortopts,$longopts,$rest) ;
if ( isset($go['help']) || isset($go['h']) ) {
  Usage();
  die();
}
if ( isset($go['color']) || isset($go['c']) ) {
  $value = isset($go['color'])  ? $go['color'] : $go['c'] ;
  if ( !isset($go['dest']) && !isset($go['d']) )
    die('Destination directory must be specified!' . PHP_EOL) ;
  echo "Color '{$value}' selected." . PHP_EOL ;
}
if ( isset($go['dest']) || isset($go['d']) ) {
  $value = isset($go['dest'])  ? $go['dest'] : $go['d'] ;
  echo "Destination directory '{$value}' selected." . PHP_EOL ;
}
var_dump($go,$rest) ;

