Add makefile, cli options
This commit is contained in:
		@@ -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
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -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 <<<ENDHELP
 | 
			
		||||
 | 
			
		||||
    Usage:
 | 
			
		||||
 | 
			
		||||
        $cmd [options] [filename]
 | 
			
		||||
 | 
			
		||||
    Options:
 | 
			
		||||
 | 
			
		||||
        -h,--help       Show this help
 | 
			
		||||
        -V,--version    Print version and exit
 | 
			
		||||
        -c              When used with a filename, load the file collapsed.
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    ENDHELP;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (isset($opts['h']) || isset($opts['help'])) {
 | 
			
		||||
    showHelp();
 | 
			
		||||
    exit(0);
 | 
			
		||||
}
 | 
			
		||||
if (isset($opts['V']) || isset($opts['version'])) {
 | 
			
		||||
    showVersion();
 | 
			
		||||
    exit(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$loadFileCollapsed = isset($opts['c']);
 | 
			
		||||
$filename = $args[0]??null;
 | 
			
		||||
 | 
			
		||||
$terminal = new NoccyLabs\JsonEdit\Terminal\Terminal();
 | 
			
		||||
 | 
			
		||||
@@ -18,7 +63,9 @@ if ($filename) {
 | 
			
		||||
} else {
 | 
			
		||||
    $editor->loadDocument((object)[]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if ($loadFileCollapsed) {
 | 
			
		||||
    $editor->doCollapseAll();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
set_exception_handler(function (\Throwable $t) use ($terminal) {
 | 
			
		||||
    register_shutdown_function(function () use ($t, $terminal)  {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user