Browse Source

Find out command (where actions are)

Serj Kalichev 2 years ago
parent
commit
e0839fe708
2 changed files with 31 additions and 26 deletions
  1. 28 26
      bin/klishd/klishd.c
  2. 3 0
      klish/ksession/ksession_parse.c

+ 28 - 26
bin/klishd/klishd.c

@@ -184,32 +184,34 @@ int main(int argc, char **argv)
 	session = ksession_new(scheme, "/lowview");
 	kpath_push(ksession_path(session), klevel_new(kscheme_find_entry_by_path(scheme, "/main")));
 	pargv = ksession_parse_line(session, line);
-	switch (kpargv_status(pargv)) {
-	case KPARSE_NONE:
-		s = "None";
-		break;
-	case KPARSE_OK:
-		s = "Ok";
-		break;
-	case KPARSE_INPROGRESS:
-		s = "In progress";
-		break;
-	case KPARSE_NOTFOUND:
-		s = "Not found";
-		break;
-	case KPARSE_INCOMPLETED:
-		s = "Incompleted";
-		break;
-	case KPARSE_ILLEGAL:
-		s = "Illegal";
-		break;
-	case KPARSE_ERROR:
-		s = "Error";
-		break;
-	}
-	printf("Level: %lu, Line '%s': %s\n", kpargv_level(pargv), line, s);
-
 	if (pargv) {
+		switch (kpargv_status(pargv)) {
+		case KPARSE_NONE:
+			s = "None";
+			break;
+		case KPARSE_OK:
+			s = "Ok";
+			break;
+		case KPARSE_INPROGRESS:
+			s = "In progress";
+			break;
+		case KPARSE_NOTFOUND:
+			s = "Not found";
+			break;
+		case KPARSE_INCOMPLETED:
+			s = "Incompleted";
+			break;
+		case KPARSE_ILLEGAL:
+			s = "Illegal";
+			break;
+		case KPARSE_ERROR:
+			s = "Error";
+			break;
+		}
+		printf("Level: %lu, Command: %s, Line '%s': %s\n",
+			kpargv_level(pargv), kentry_name(kpargv_command(pargv)),
+			line, s);
+
 		kparg_t *parg = NULL;
 		p_iter = kpargv_pargs_iter(pargv);
 		while ((parg = kpargv_pargs_each(&p_iter))) {
@@ -217,7 +219,7 @@ int main(int argc, char **argv)
 		}
 		printf("\n");
 	}
-	
+
 	kpargv_free(pargv);
 	ksession_free(session);
 	

+ 3 - 0
klish/ksession/ksession_parse.c

@@ -66,6 +66,9 @@ static kpargv_status_e ksession_parse_arg(kentry_t *current_entry,
 		if (ksession_validate_arg(entry, current_arg)) {
 			kparg_t *parg = kparg_new(entry, current_arg);
 			kpargv_add_parg(pargv, parg);
+			// Command is an ENTRY with ACTIONs or NAVigation
+			if (kentry_actions_len(entry) > 0)
+				kpargv_set_command(pargv, entry);
 			faux_argv_each(argv_iter); // Next argument
 			retcode = KPARSE_INPROGRESS;
 		} else {