Skip to contentSkip to conversation

main: Error out when combining -i/--interactive and -f/--file

PATCH New Pablo Neira Ayuso 1 participant 1 message Apr 8, 2023

Subsystems (3)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 main: Error out when combining -i/--interactive and -f/--file

These two options are mutually exclusive, display error in that case:

 # nft -i -f test.nft
 Error: -i/--interactive and -f/--file options cannot be combined
---
 src/main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
src/main.c +10 -0
index 9bd25db82343..cb20850b71c5 100644
@@ -405,9 +405,19 @@ int main(int argc, char * const *argv)
 			nft_ctx_set_dry_run(nft, true);
 			break;
 		case OPT_FILE:
+			if (interactive) {
+				fprintf(stderr,
+					"Error: -i/--interactive and -f/--file options cannot be combined\n");
+				exit(EXIT_FAILURE);
+			}
 			filename = optarg;
 			break;
 		case OPT_INTERACTIVE:
+			if (filename) {
+				fprintf(stderr,
+					"Error: -i/--interactive and -f/--file options cannot be combined\n");
+				exit(EXIT_FAILURE);
+			}
 			interactive = true;
 			break;
 		case OPT_INCLUDEPATH:
Signature · 1 line
2.30.2