From eb09b4698f5b3fababebf8a0a67f113d5543f8b7 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sat, 5 Oct 2024 16:34:49 +0200 Subject: [PATCH] Add makefile, cli options --- Makefile | 7 ++++++ src/Editor/Editor.php | 35 ++++++++++++++++------------- src/entry.php | 51 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..731f861 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: jsonedit.phar +jsonedit.phar: + echo " \"v$(shell git describe --tags)\", 'builddate' => \"$(shell LC_ALL=C date)\" ];" > src/build.php \ + && box compile \ + && rm src/build.php \ + && mv bin/jsonedit.phar . + diff --git a/src/Editor/Editor.php b/src/Editor/Editor.php index 7441554..232d7e7 100644 --- a/src/Editor/Editor.php +++ b/src/Editor/Editor.php @@ -261,21 +261,7 @@ class Editor break; case "-": - foreach ($this->list as $path => $entry) { - $node = $entry->node; - if ($path == "/") { - if ($node instanceof CollapsibleNode) { - $node->collapse(false); - } - } else { - if ($node instanceof CollapsibleNode) { - $node->collapse(true); - } - } - } - $this->currentRow = 0; - $this->list->parseTree(); - $this->redrawEditor(); + $this->doCollapseAll(); break; case "k{LEFT}": @@ -732,6 +718,25 @@ class Editor } } + public function doCollapseAll(): void + { + foreach ($this->list as $path => $entry) { + $node = $entry->node; + if ($path == "/") { + if ($node instanceof CollapsibleNode) { + $node->collapse(false); + } + } else { + if ($node instanceof CollapsibleNode) { + $node->collapse(true); + } + } + } + $this->currentRow = 0; + $this->list->parseTree(); + $this->redrawEditor(); + } + /** * Ask for input * diff --git a/src/entry.php b/src/entry.php index a8209b0..4958fd0 100644 --- a/src/entry.php +++ b/src/entry.php @@ -4,9 +4,54 @@ use NoccyLabs\JsonEdit\Settings; require_once __DIR__."/../vendor/autoload.php"; +if (file_exists(__DIR__."/build.php")) { + $buildInfo = include __DIR__."/build.php"; +} else { + $buildInfo = []; +} +define("APP_VERSION", $buildInfo['version']??"DEV"); +define("APP_BUILDDATE", $buildInfo['builddate']??"now"); + define("SETTINGS_FILE", getenv("HOME")."/.config/jsonedit/config.json"); -$filename = $argv[1]??null; +$opts = getopt("hVc", [ "help", "version" ], $optind); +$args = array_slice($argv,$optind); + +function showVersion() { + echo "JSONEdit ".APP_VERSION." (built: ".APP_BUILDDATE.")\n"; + echo "(c) 2024, NoccyLabs. Licensed under GNU GPL version 3 or later\n"; +} +function showHelp() { + global $argv; + $cmd = basename($argv[0]); + showVersion(); + echo <<loadDocument((object)[]); } - +if ($loadFileCollapsed) { + $editor->doCollapseAll(); +} set_exception_handler(function (\Throwable $t) use ($terminal) { register_shutdown_function(function () use ($t, $terminal) {