From 3dcac6bdded4f39767fdd84f2f85bcafed74ddfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=BB=E6=B5=B7=E9=92=A7?= <826245622@qq.com> Date: Sun, 26 Apr 2020 15:17:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90TODO=20=20execfile=20?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E6=94=AF=E6=8C=81=E6=90=BA=E5=B8=A6=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E5=8F=82=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 3 ++- pypssh.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 53019eb..13bbf4c 100644 --- a/TODO.md +++ b/TODO.md @@ -10,6 +10,7 @@ ### In Progress -### Done ✓ +### Done +- [易用性需求:2020年4月26日] execfile 指令支持携带脚本参数。 diff --git a/pypssh.py b/pypssh.py index a003e00..b1687ba 100644 --- a/pypssh.py +++ b/pypssh.py @@ -154,13 +154,17 @@ def _ssh_test(host): # 远程执行脚本文件,可以从配置文件加载变量,可以读参数变量 @cli.command() @click.argument('script_file', type=click.types.Path()) +@click.argument('script_arg', type = str, nargs = -1, required = False) @click.option('-a','--arg',type=str,multiple=True,required=False) @click.option('--show/--no-show',default=True,type=bool) @click.option('--pty',default=True,type=bool,required=False) @click.pass_context -def execfile(ctx, script_file, arg, show, pty): +def execfile(ctx, script_file, script_arg, arg, show, pty): ctx.invoke(put, local_file=script_file, remote_file="/tmp/.pypssh/tmp") - command = ''.join(["export %s && "%item for item in arg]) + "chmod +x /tmp/.pypssh/tmp && /tmp/.pypssh/tmp" + script_env = ''.join(["export %s && "%item for item in arg]) + script_arg_str = ' '.join(script_arg) + command = f"{script_env} chmod +x /tmp/.pypssh/tmp && /tmp/.pypssh/tmp {script_arg_str}" + logger.debug(command) ctx.invoke(execute, command=command, show=show, pty=pty)