Skip to content

Commit 0a2c747

Browse files
protocolstardustsingaraiona
authored andcommitted
feat(startup) - Add flag to disable REPL (daemon mode)
1 parent 848198a commit 0a2c747

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

app/main.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ i32_t main(i32_t argc, str_p argv[]) {
5757
i32_t code = -1;
5858
sys_info_t *info;
5959
runtime_p runtime;
60-
obj_p interactive_arg, port_arg, file_arg, res, fmt;
60+
obj_p interactive_arg, port_arg, file_arg, repl_arg, res, fmt;
6161
b8_t interactive = B8_FALSE;
6262
b8_t has_file = B8_FALSE;
6363
b8_t file_error = B8_FALSE;
64+
b8_t repl_disabled = B8_FALSE;
6465

6566
runtime = runtime_create(argc, argv);
6667
if (runtime == NULL)
@@ -71,6 +72,14 @@ i32_t main(i32_t argc, str_p argv[]) {
7172
interactive = !is_null(interactive_arg);
7273
drop_obj(interactive_arg);
7374

75+
// Check if REPL is explicitly disabled (-r 0)
76+
repl_arg = runtime_get_arg("repl");
77+
if (!is_null(repl_arg)) {
78+
if (repl_arg->len == 1 && AS_C8(repl_arg)[0] == '0')
79+
repl_disabled = B8_TRUE;
80+
}
81+
drop_obj(repl_arg);
82+
7483
// Check if port is specified (-p/--port) — implies server mode
7584
port_arg = runtime_get_arg("port");
7685
if (!is_null(port_arg))
@@ -104,14 +113,16 @@ i32_t main(i32_t argc, str_p argv[]) {
104113

105114
// Interactive mode: no file, or file with -i flag
106115
// Only show logo and REPL if stdin is a TTY (not piped input)
107-
if (isatty(STDIN_FILENO)) {
116+
if (!repl_disabled && isatty(STDIN_FILENO)) {
108117
info = &runtime_get()->sys_info;
109118
print_logo(info);
110119
}
111120

112121
// Create REPL for interactive mode (handles both TTY and piped input)
122+
// When REPL is disabled (-r 0), skip entirely — daemon/server mode:
123+
// the event loop runs with only the port listener, no stdin interaction.
113124
repl_p repl = NULL;
114-
if (runtime->poll)
125+
if (!repl_disabled && runtime->poll)
115126
repl = repl_create(runtime->poll);
116127

117128
code = runtime_run();

core/runtime.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
runtime_p __RUNTIME = NULL;
3535

3636
nil_t usage(nil_t) {
37-
printf("%s%s%s", BOLD, YELLOW, "Usage: rayforce [-f file] [-p port] [-t timeit] [-c cores] [-i] [file]\n");
37+
printf("%s%s%s", BOLD, YELLOW, "Usage: rayforce [-f file] [-p port] [-t timeit] [-c cores] [-i] [-r 0|1 REPL mode] [file]\n");
3838
exit(EXIT_FAILURE);
3939
}
4040

@@ -73,6 +73,12 @@ obj_p parse_cmdline(i32_t argc, str_p argv[]) {
7373
push_sym(&keys, "timeit");
7474
str = string_from_str(argv[opt], strlen(argv[opt]));
7575
push_obj(&vals, str);
76+
} else if (!user_defined && (strcmp(flag, "r") == 0 || strcmp(flag, "repl") == 0)) {
77+
if (++opt >= argc)
78+
usage();
79+
push_sym(&keys, "repl");
80+
str = string_from_str(argv[opt], strlen(argv[opt]));
81+
push_obj(&vals, str);
7682
} else if (!user_defined && (strcmp(flag, "i") == 0 || strcmp(flag, "interactive") == 0)) {
7783
// -i/--interactive is a boolean flag, no value needed
7884
push_sym(&keys, "interactive");

0 commit comments

Comments
 (0)