<?php # -*- coding: utf-8 mode: php -*- vim:sw=2:sts=2:et:ai:si:sta:fenc=utf-8
require(__DIR__.'/../../vendor/autoload.php');

use nur\cli\Application;
use nur\cli\DynamicCommand;

class Test3DynamicCommand extends DynamicCommand {
  const COMMANDS = [
    "dyn1" => ["d1",
      "help" => "dynamic command 1",
      "cmd_args" => [
        ["-o", "--d1-option"],
        ["-v:", "--d1-value"],
      ],
    ],
    "dyn2" => ["d2",
      "help" => "dynamic command 2",
      "cmd_args" => [
        ["-o", "--d2-option"],
        ["-v:", "--d2-value"],
      ],
    ],
  ];
}

Application::run(new class extends Application {
  const ARGS = [
    #"dynamic_command" => [self::class, "get_dynamic_command"],
    "dynamic_command" => Test3DynamicCommand::class,
    ["-o", "--option"],
    ["-v:", "--value"],
    ["static", "s",
      "help" => "static command",
      "cmd_args" => [
        ["-o", "--s-option"],
        ["-v:", "--s-value"],
      ],
    ],
  ];

  static function get_dynamic_command(string $command): ?array {
    switch ($command) {
    case "d1": return Test3DynamicCommand::COMMANDS["d1"];
    case "d2": return Test3DynamicCommand::COMMANDS["d2"];
    default: return null;
    }
  }

  private $option, $value, $args, $command;

  function main() {
    Txx("option", $this->option, "value", $this->value);
    Txx("args", $this->args);
    Txx("command", $this->command);
  }
});