<?php
namespace nulib\tools;

use nulib\app\cli\Application;
use nulib\ext\json;
use nulib\ext\yaml;
use nulib\os\path;

class Yaml2jsonApp extends Application {
  private $args;

  function main() {
    $input = $this->args[0] ?? null;
    if ($input === null || $input === "-") {
      $output = null;
    } else {
      $output = path::ensure_ext($input, ".json", [".yml", ".yaml"]);
    }

    $data = yaml::load($input);
    json::dump($data, $output);
  }
}