<?php
namespace nulib\cli;

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

class Json2yamlApp extends Application {
  private $args;

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

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