feat: add --exec command line option

This allows you to execute mini scripts on flow startup.

For example to change flow's whitespace setting:

`flow --exec toggle_whitespace --exec quit'

Or open and move to the end of a file:

`flow src/main.zig --exec move_buffer_end`
This commit is contained in:
CJ van den Berg 2024-07-30 22:16:52 +02:00
parent 23e0a88c0c
commit 9139e3f9ad

View file

@ -41,6 +41,7 @@ pub fn main() anyerror!void {
\\--show-log Open the log view on start. \\--show-log Open the log view on start.
\\-l, --language <lang> Force the language of the file to be opened. \\-l, --language <lang> Force the language of the file to be opened.
\\--list-languages Show available languages. \\--list-languages Show available languages.
\\-e, --exec <command>... Execute a command on startup.
\\-v, --version Show build version and exit. \\-v, --version Show build version and exit.
\\<file>... File or directory to open. \\<file>... File or directory to open.
\\ Add +<LINE> to the command line or append \\ Add +<LINE> to the command line or append
@ -60,6 +61,7 @@ pub fn main() anyerror!void {
.num = clap.parsers.int(usize, 10), .num = clap.parsers.int(usize, 10),
.lang = clap.parsers.string, .lang = clap.parsers.string,
.file = clap.parsers.string, .file = clap.parsers.string,
.command = clap.parsers.string,
}; };
var diag = clap.Diagnostic{}; var diag = clap.Diagnostic{};
@ -241,6 +243,9 @@ pub fn main() anyerror!void {
try tui_proc.send(.{ "cmd", "open_project_cwd" }); try tui_proc.send(.{ "cmd", "open_project_cwd" });
try tui_proc.send(.{ "cmd", "show_home" }); try tui_proc.send(.{ "cmd", "show_home" });
} }
for (res.args.exec) |cmd| try tui_proc.send(.{ "cmd", cmd, .{} });
ctx.run(); ctx.run();
if (want_restart) restart(); if (want_restart) restart();