Skip to content

Commit

Permalink
完成TODO execfile 指令支持携带脚本参数。
Browse files Browse the repository at this point in the history
  • Loading branch information
闻海钧 committed Apr 26, 2020
1 parent dae8865 commit 3dcac6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### In Progress


### Done ✓
### Done
- [易用性需求:2020年4月26日] execfile 指令支持携带脚本参数。


8 changes: 6 additions & 2 deletions pypssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 3dcac6b

Please sign in to comment.