diff cmd.c @ 13:cf81eb0c2d5a

Warn before quitting if there are unsaved changes If there are unsaved changes emit a warning when the quit command is used. Only quit if the quit command is used twice with no other command in between. Add a new Quit command which immediatly quits pwm without a warning.
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Mon, 07 Aug 2017 16:59:47 +0200
parents 8768fbd09bc5
children a01899a6e4bb
line wrap: on
line diff
--- a/cmd.c	Thu Aug 03 10:22:07 2017 +0200
+++ b/cmd.c	Mon Aug 07 16:59:47 2017 +0200
@@ -172,6 +172,7 @@
     { "h", "help", "help", "Show help text", cmd_help },
     { "w", "write", "write", "Write the database", cmd_write },
     { "q", "quit", "quit", "Quit", cmd_quit },
+    { "Q", "Quit", "Quit", "Quit without checking", cmd_quit },
     { 0 }
 };
 
@@ -911,6 +912,12 @@
 		return (CMD_USAGE);
 	}
 
+	if ((argv[0][0] == 'q') && ctx->unsaved_changes &&
+	    (ctx->prev_cmd != NULL) && (strcmp(ctx->prev_cmd, "quit") != 0)) {
+		printf("Warning: There are unsaved changes\n");
+		return (CMD_OK);
+	}
+
 	return (CMD_QUIT);
 }