From 22bc4e2cfcf73ae80d3c7a950b4abcd994ca4fd1 Mon Sep 17 00:00:00 2001
From: Alexander Kurdakov <a.kurdakov@picodata.io>
Date: Tue, 5 Sep 2023 06:31:10 +0000
Subject: [PATCH] feat: add interactive mode flag to cli

---
 CHANGELOG.md |  2 ++
 src/args.rs  | 27 ++++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72ef771742..7ca94ce820 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,8 @@ with the `YY.0M.MICRO` scheme.
 
 - _Clusterwide SQL_ now availiable via `\set language sql` in interactive console.
 
+- Interactive console is disabled by default. Enable it implicitly with `picodata run -i`.
+
 - Allow specifying `picodata connect [user@][host][:port]` format. It
   overrides the `--user` option.
 
diff --git a/src/args.rs b/src/args.rs
index 9ce2d1dfe0..2c1a33f414 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -134,6 +134,10 @@ pub struct Run {
     /// in Lua as `_G.pico.httpd` variable. If not specified, it won't
     /// be initialized.
     pub http_listen: Option<Address>,
+
+    #[clap(short = 'i', long = "interactive", env = "PICODATA_INTERACTIVE_MODE")]
+    /// Enable interactive console
+    pub interactive_mode: bool,
 }
 
 // Copy enum because clap:ArgEnum can't be derived for the foreign SayLevel.
@@ -168,7 +172,17 @@ impl From<LogLevel> for SayLevel {
 impl Run {
     /// Get the arguments that will be passed to `tarantool_main`
     pub fn tt_args(&self) -> Result<Vec<CString>, String> {
-        Ok(vec![current_exe()?])
+        let mut args = vec![
+            current_exe()?,
+            CString::new(r"-e").unwrap(),
+            CString::new(r#" "#).unwrap(),
+        ];
+
+        if self.interactive_mode {
+            args.push(CString::new("-i").unwrap());
+        }
+
+        Ok(args)
     }
 
     pub fn advertise_address(&self) -> String {
@@ -729,6 +743,17 @@ mod tests {
             assert_eq!(parsed.init_replication_factor, 9);
         }
 
+        {
+            let parsed = parse![Run, "-i"];
+            assert_eq!(parsed.interactive_mode, true);
+
+            let parsed = parse![Run, "--interactive"];
+            assert_eq!(parsed.interactive_mode, true);
+
+            let parsed = parse![Run,];
+            assert_eq!(parsed.interactive_mode, false);
+        }
+
         {
             let parsed = parse![Connect, "somewhere:3301"];
             assert_eq!(parsed.user, "guest");
-- 
GitLab