Browse Source

Add --check option to clish. To check config files

git-svn-id: https://klish.googlecode.com/svn/trunk@519 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
7266c16269
2 changed files with 19 additions and 5 deletions
  1. 8 1
      bin/clish.cpp
  2. 11 4
      clish/shell/shell_tinyrl.c

+ 8 - 1
bin/clish.cpp

@@ -72,7 +72,7 @@ int main(int argc, char **argv)
 	struct sigaction sigpipe_act;
 	sigset_t sigpipe_set;
 
-	static const char *shortopts = "hvs:ledx:w:i:bqu8o";
+	static const char *shortopts = "hvs:ledx:w:i:bqu8ok";
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
 		{"help",	0, NULL, 'h'},
@@ -89,6 +89,7 @@ int main(int argc, char **argv)
 		{"utf8",	0, NULL, 'u'},
 		{"8bit",	0, NULL, '8'},
 		{"log",		0, NULL, 'o'},
+		{"check",	0, NULL, 'k'},
 		{NULL,		0, NULL, 0}
 	};
 #endif
@@ -154,6 +155,11 @@ int main(int argc, char **argv)
 		case 'i':
 			viewid = optarg;
 			break;
+		case 'k':
+			lockless = BOOL_TRUE;
+			my_hooks.script_fn = clish_dryrun_callback;
+			my_hooks.config_fn = NULL;
+			break;
 		case 'h':
 			help(0, argv[0]);
 			exit(0);
@@ -282,6 +288,7 @@ static void help(int status, const char *argv0)
 		printf("\t-u, --utf8\tForce UTF-8 encoding.\n");
 		printf("\t-8, --8bit\tForce 8-bit encoding.\n");
 		printf("\t-o, --log\tEnable command logging to syslog's local0.\n");
+		printf("\t-k, --check\tCheck input files for syntax errors only.\n");
 	}
 }
 

+ 11 - 4
clish/shell/shell_tinyrl.c

@@ -254,22 +254,29 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 		/* we've got a command so check the syntax */
 		arg_status = clish_shell_parse(context->shell,
 			line, &context->cmd, &context->pargv);
+		if (CLISH_LINE_OK != arg_status) {
+			fprintf(stderr, "Syntax error on line \"%s\":\n",
+				line);
+		}
 		switch (arg_status) {
 		case CLISH_LINE_OK:
 			tinyrl_done(this);
 			result = BOOL_TRUE;
 			break;
 		case CLISH_BAD_HISTORY:
-			fprintf(stderr, "Error: Bad history entry.\n");
+			fprintf(stderr, "Bad history entry.\n");
 			break;
 		case CLISH_BAD_CMD:
-			fprintf(stderr, "Error: Illegal command line.\n");
+			fprintf(stderr, "Illegal command line.\n");
 			break;
 		case CLISH_BAD_PARAM:
-			fprintf(stderr, "Error: Illegal parameter.\n");
+			fprintf(stderr, "Illegal parameter.\n");
 			break;
 		case CLISH_LINE_PARTIAL:
-			fprintf(stderr, "Error: The command is not completed.\n");
+			fprintf(stderr, "The command is not completed.\n");
+			break;
+		default:
+			fprintf(stderr, "Unknown problem.\n");
 			break;
 		}
 		if (CLISH_LINE_OK != arg_status)