浏览代码

cmd_shell: option to run without saving commands history

Daniel-Constantin Mierla 5 年之前
父节点
当前提交
27a642fedd
共有 1 个文件被更改,包括 18 次插入8 次删除
  1. 18 8
      kamcli/commands/cmd_shell.py

+ 18 - 8
kamcli/commands/cmd_shell.py

@@ -333,17 +333,27 @@ def handle_internal_commands(command):
             return target()
 
 
[email protected]("shell", short_help="Run in shell mode")
[email protected]("shell", short_help="Run in interactive shell mode")
[email protected](
+    "nohistory",
+    "--no-history",
+    "-n",
+    is_flag=True,
+    help="Do not save commands history",
+)
 @pass_context
-def cli(ctx):
+def cli(ctx, nohistory):
     """Run in shell mode
 
     \b
     """
-    if not os.path.isdir(os.path.expanduser("~/.kamcli")):
-        os.mkdir(os.path.expanduser("~/.kamcli"))
+    if nohistory:
+        shell_repl(click.get_current_context())
+    else:
+        if not os.path.isdir(os.path.expanduser("~/.kamcli")):
+            os.mkdir(os.path.expanduser("~/.kamcli"))
 
-    prompt_kwargs = {
-        "history": FileHistory(os.path.expanduser("~/.kamcli/history")),
-    }
-    shell_repl(click.get_current_context(), prompt_kwargs=prompt_kwargs)
+        prompt_kwargs = {
+            "history": FileHistory(os.path.expanduser("~/.kamcli/history")),
+        }
+        shell_repl(click.get_current_context(), prompt_kwargs=prompt_kwargs)