Skip to content

Commit df38ec9

Browse files
ptaffet-jumpmmcgee-jump
authored andcommitted
app: only certain subcommands require config
1 parent bf8d499 commit df38ec9

File tree

9 files changed

+47
-41
lines changed

9 files changed

+47
-41
lines changed

src/app/shared/boot/fd_boot.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,20 @@ fd_main( int argc,
193193
example, they want to show the version or validate the produced
194194
binary without yet setting up the full TOML. */
195195

196-
if( FD_UNLIKELY( !argc ) ) {
197-
for( ulong i=0UL; ACTIONS[ i ]; i++ ) {
198-
action_t * action = ACTIONS[ i ];
199-
if( FD_UNLIKELY( action->is_help ) ) {
200-
action->fn( NULL, NULL );
201-
FD_LOG_WARNING(( "no subcommand specified, exiting" ));
202-
return 1;
203-
}
196+
action_t * help_action = NULL;
197+
for( ulong i=0UL; ACTIONS[ i ]; i++ ) {
198+
if( FD_UNLIKELY( ACTIONS[ i ]->is_help ) ) {
199+
help_action = ACTIONS[ i ];
200+
break;
204201
}
205202
}
206203

204+
if( FD_UNLIKELY( !argc ) ) {
205+
help_action->fn( NULL, NULL );
206+
FD_LOG_WARNING(( "no subcommand specified, exiting" ));
207+
return 1;
208+
}
209+
207210
/* We need to strip away (potentially leading) cmdline flags first,
208211
since the parser assumes the action is the leading argument */
209212
const char * opt_user_config_path = fd_env_strip_cmdline_cstr(
@@ -230,19 +233,14 @@ fd_main( int argc,
230233

231234
int is_local_cluster = action ? action->is_local_cluster : 0;
232235
fd_main_init( &argc, &argv, &config, opt_user_config_path, is_firedancer, is_local_cluster, NULL, default_config, default_config_sz, topo_init );
233-
if( FD_UNLIKELY( !opt_user_config_path ) ) FD_LOG_ERR(( "missing required `--config` argument" ));
234236

235237
if( FD_UNLIKELY( !action ) ) {
236-
for( ulong i=0UL; ACTIONS[ i ]; i++ ) {
237-
action_t * action = ACTIONS[ i ];
238-
if( FD_UNLIKELY( action->is_help ) ) {
239-
action->fn( NULL, NULL );
240-
break;
241-
}
242-
}
238+
help_action->fn( NULL, NULL );
243239
FD_LOG_ERR(( "unknown subcommand `%s`", argv[ 0 ] ));
244240
}
245241

242+
if( FD_UNLIKELY( action->require_config && !opt_user_config_path ) ) FD_LOG_ERR(( "missing required `--config` argument" ));
243+
246244
argc--; argv++;
247245

248246
args_t args = {0};

src/app/shared/commands/mem.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ mem_cmd_fn( args_t * args FD_PARAM_UNUSED,
88
}
99

1010
action_t fd_action_mem = {
11-
.name = "mem",
12-
.args = NULL,
13-
.fn = mem_cmd_fn,
14-
.perm = NULL,
15-
.description = "Print workspace memory and tile topology information",
11+
.name = "mem",
12+
.args = NULL,
13+
.fn = mem_cmd_fn,
14+
.require_config = 1,
15+
.perm = NULL,
16+
.description = "Print workspace memory and tile topology information",
1617
};

src/app/shared/commands/monitor/monitor.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,10 @@ monitor_cmd_fn( args_t * args,
622622
}
623623

624624
action_t fd_action_monitor = {
625-
.name = "monitor",
626-
.args = monitor_cmd_args,
627-
.fn = monitor_cmd_fn,
628-
.perm = monitor_cmd_perm,
629-
.description = "Monitor a locally running Firedancer instance with a terminal GUI",
625+
.name = "monitor",
626+
.args = monitor_cmd_args,
627+
.fn = monitor_cmd_fn,
628+
.require_config = 1,
629+
.perm = monitor_cmd_perm,
630+
.description = "Monitor a locally running Firedancer instance with a terminal GUI",
630631
};

src/app/shared/commands/netconf.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ netconf_cmd_fn( args_t * args,
6464
}
6565

6666
action_t fd_action_netconf = {
67-
.name = "netconf",
68-
.args = NULL,
69-
.fn = netconf_cmd_fn,
70-
.perm = NULL,
71-
.description = "Print network configuration",
67+
.name = "netconf",
68+
.args = NULL,
69+
.fn = netconf_cmd_fn,
70+
.require_config = 1,
71+
.perm = NULL,
72+
.description = "Print network configuration",
7273
};

src/app/shared/commands/ready.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ ready_cmd_fn( args_t * args FD_PARAM_UNUSED,
4040
}
4141

4242
action_t fd_action_ready = {
43-
.name = "ready",
44-
.args = NULL,
45-
.fn = ready_cmd_fn,
46-
.perm = NULL,
47-
.description = "Wait for all tiles to be running",
43+
.name = "ready",
44+
.args = NULL,
45+
.fn = ready_cmd_fn,
46+
.require_config = 1,
47+
.perm = NULL,
48+
.description = "Wait for all tiles to be running",
4849
};

src/app/shared/commands/run/run.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ action_t fd_action_run = {
899899
.name = "run",
900900
.args = NULL,
901901
.fn = run_cmd_fn,
902+
.require_config = 1,
902903
.perm = run_cmd_perm,
903904
.description = "Start up a Firedancer validator",
904905
.permission_err = "insufficient permissions to execute command `%s`. It is recommended "

src/app/shared/commands/set_identity.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,10 @@ set_identity_cmd_fn( args_t * args,
385385
}
386386

387387
action_t fd_action_set_identity = {
388-
.name = "set-identity",
389-
.args = set_identity_cmd_args,
390-
.fn = set_identity_cmd_fn,
391-
.perm = NULL,
392-
.description = "Change the identity of a running validator",
388+
.name = "set-identity",
389+
.args = set_identity_cmd_args,
390+
.fn = set_identity_cmd_fn,
391+
.require_config = 1,
392+
.perm = NULL,
393+
.description = "Change the identity of a running validator",
393394
};

src/app/shared/commands/version.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ action_t fd_action_version = {
1717
.args = NULL,
1818
.fn = version_cmd_fn,
1919
.perm = NULL,
20+
.is_immediate= 1,
2021
.description = "Show the current software version",
2122
};

src/app/shared/fd_action.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct fd_action {
100100

101101
int is_help;
102102
int is_immediate;
103+
int require_config; /* halt if the user tries to use the default config */
103104
int is_local_cluster; /* If a command is one which runs a local cluster, certain information in
104105
the configuration file will be changed. */
105106
uchar is_diagnostic; /* 1 implies action should be allowed for prod debugging */

0 commit comments

Comments
 (0)