nulib-base/php/cli/Json2yamlApp.php

21 lines
426 B
PHP

<?php
namespace cli;
use nulib\app\cli\Application;
use nulib\ext\json;
use nulib\ext\yaml;
use nulib\os\path;
class Json2yamlApp extends Application {
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);
}
}