Browse Source

klish: Dry-run for interactive session

Serj Kalichev 1 year ago
parent
commit
1d416e98ad
3 changed files with 8 additions and 4 deletions
  1. 6 2
      bin/klish/interactive.c
  2. 1 1
      bin/klish/klish.c
  3. 1 1
      bin/klish/private.h

+ 6 - 2
bin/klish/interactive.c

@@ -11,11 +11,14 @@
 #include <klish/ktp_session.h>
 #include <tinyrl/tinyrl.h>
 
+#include "private.h"
+
 
 // Context for main loop
 typedef struct ctx_s {
 	ktp_session_t *ktp;
 	tinyrl_t *tinyrl;
+	struct options *opts;
 } ctx_t;
 
 
@@ -27,7 +30,7 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key);
 
 
-int klish_interactive_shell(ktp_session_t *ktp)
+int klish_interactive_shell(ktp_session_t *ktp, struct options *opts)
 {
 	ctx_t ctx = {};
 	faux_eloop_t *eloop = NULL;
@@ -50,6 +53,7 @@ int klish_interactive_shell(ktp_session_t *ktp)
 
 	ctx.ktp = ktp;
 	ctx.tinyrl = tinyrl;
+	ctx.opts = opts;
 
 	// Don't stop interactive loop on each answer
 	ktp_session_set_stop_on_answer(ktp, BOOL_FALSE);
@@ -127,7 +131,7 @@ static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key)
 	if (faux_str_is_empty(line))
 		return BOOL_TRUE;
 
-	ktp_session_cmd(ctx->ktp, line, error, BOOL_FALSE);
+	ktp_session_cmd(ctx->ktp, line, error, ctx->opts->dry_run);
 
 	tinyrl_reset_line(tinyrl);
 	tinyrl_set_busy(tinyrl, BOOL_TRUE);

+ 1 - 1
bin/klish/klish.c

@@ -152,7 +152,7 @@ int main(int argc, char **argv)
 	// Interactive shell
 	} else {
 		// Interactive code is complex so move it to separate file
-		retcode = klish_interactive_shell(ktp);
+		retcode = klish_interactive_shell(ktp, opts);
 	}
 
 	retval = 0;

+ 1 - 1
bin/klish/private.h

@@ -26,4 +26,4 @@ void opts_free(struct options *opts);
 int opts_parse(int argc, char *argv[], struct options *opts);
 
 // Interactive shell
-int klish_interactive_shell(ktp_session_t *ktp);
+int klish_interactive_shell(ktp_session_t *ktp, struct options *opts);