Browse Source

Incomplete command is legal for clish_shell_resolve_command()

Serj Kalichev 2 years ago
parent
commit
67eeac5f72
4 changed files with 38 additions and 27 deletions
  1. 1 0
      clish/command.h
  2. 26 0
      clish/command/command.c
  3. 10 9
      clish/shell/shell_help.c
  4. 1 18
      clish/view/view.c

+ 1 - 0
clish/command.h

@@ -75,5 +75,6 @@ int clish_command__get_depth(const clish_command_t * instance);
 clish_view_restore_e clish_command__get_restore(const clish_command_t * instance);
 const clish_command_t * clish_command__get_orig(const clish_command_t * instance);
 const clish_command_t * clish_command__get_cmd(const clish_command_t * instance);
+bool_t clish_command_is_incomplete(const clish_command_t *instance);
 
 #endif				/* _clish_command_h */

+ 26 - 0
clish/command/command.c

@@ -298,3 +298,29 @@ const clish_command_t * clish_command__get_cmd(const clish_command_t * this)
 		return clish_command__get_cmd(this->link);
 	return NULL;
 }
+
+/*--------------------------------------------------------- */
+/* Consider command incomplete when it doesn't have any actions to execute.
+   I.e. has no ACTION, doesn't change VIEW, doesn't have CONFIG tag.
+ */
+bool_t clish_command_is_incomplete(const clish_command_t *this)
+{
+	clish_action_t *action = NULL;
+	clish_config_t *config = NULL;
+
+	assert(this);
+	if (!this)
+		return BOOL_TRUE; // Empty command is incomplete
+
+	action = clish_command__get_action(this);
+	config = clish_command__get_config(this);
+	if (!clish_action__get_script(action) &&
+		!clish_action__get_builtin(action) &&
+		(CLISH_CONFIG_NONE == clish_config__get_op(config)) &&
+		!clish_command__get_param_count(this) &&
+		!clish_command__get_viewname(this)) {
+		return BOOL_TRUE;
+	}
+
+	return BOOL_FALSE;
+}

+ 10 - 9
clish/shell/shell_help.c

@@ -42,14 +42,15 @@ static int available_params(clish_shell_t *this,
 	clish_help_t *help, const clish_command_t *cmd,
 	const char *line, size_t *max_width)
 {
-	unsigned index = lub_string_wordcount(line);
-	unsigned idx = lub_string_wordcount(clish_command__get_name(cmd));
-	lub_argv_t *argv;
-	clish_pargv_t *completion, *pargv;
-	unsigned i;
-	unsigned cnt = 0;
+	unsigned int index = lub_string_wordcount(line);
+	unsigned int idx = lub_string_wordcount(clish_command__get_name(cmd));
+	lub_argv_t *argv = NULL;
+	clish_pargv_t *completion = NULL;
+	clish_pargv_t *pargv = NULL;
+	unsigned int i = 0;
+	unsigned int cnt = 0;
 	clish_pargv_status_e status = CLISH_LINE_OK;
-	clish_context_t context;
+	clish_context_t context = {};
 
 	/* Empty line */
 	if (0 == index)
@@ -77,8 +78,8 @@ static int available_params(clish_shell_t *this,
 
 	/* Calculate the longest name */
 	for (i = 0; i < cnt; i++) {
-		const clish_param_t *param;
-		const char *name;
+		const clish_param_t *param = NULL;
+		const char *name = NULL;
 		unsigned clen = 0;
 
 		param = clish_pargv__get_param(completion, i);

+ 1 - 18
clish/view/view.c

@@ -182,24 +182,7 @@ clish_command_t *clish_view_resolve_prefix(clish_view_t * this,
 clish_command_t *clish_view_resolve_command(clish_view_t *this,
 	const char *line, bool_t inherit)
 {
-	clish_command_t *result = clish_view_resolve_prefix(this, line, inherit);
-
-	if (result) {
-		clish_action_t *action = clish_command__get_action(result);
-		clish_config_t *config = clish_command__get_config(result);
-		if (!clish_action__get_script(action) &&
-			(!clish_action__get_builtin(action)) &&
-			(CLISH_CONFIG_NONE == clish_config__get_op(config)) &&
-			(!clish_command__get_param_count(result)) &&
-			(!clish_command__get_viewname(result))) {
-			/* if this doesn't do anything we've
-			 * not resolved a command
-			 */
-			result = NULL;
-		}
-	}
-
-	return result;
+	return clish_view_resolve_prefix(this, line, inherit);
 }
 
 /*--------------------------------------------------------- */