-
Notifications
You must be signed in to change notification settings - Fork 299
Password as CLI argument #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It would be preferable to specify the password using a switch, like Also, please don't use f-strings, they will only work with very recent versions of CPython. |
Multiple files are not supported so it's OK, one need a single glance on format to realize it. However, if you insist on |
I hope it's OK if |
Better to let it appear anywhere. And no, you don't need to write another argparse for this (e.g. it's ok to assume -p and the actual password will be separated by a space). |
IMHO adding so much abstract arguments syntax is not a MicroPython way either, but OK, I'll try to do it with not very many lines and changes... |
There's definitely another alternative, which we followed so far: to treat a webrepl client implementation here as a simple, reference one and let community develop "value added" tools using it as an example. But if there's desire to add a password arg to the reference client, it apparently should be done to not potentially confuse users (not in an adhoc way). |
"value added" tools are not good in this case, because passwords should never be hardcoded inside tools. Password should be near host address or nowhere. Following the no ad-hoc code way I also got rid of this e9ff506#diff-275e901131ecb58a8c9fee40909d64c0L224 There are still two unconditional |
how about merge? *_* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Himura2la for updating the patch. But please note that the MicroPython philosophy of minimal and clean code applies not only to the core VM/runtime but also to the tools like this one. To that end there's a much simpler way to support optional args which allows to more easily add other options than the way you did it. Eg something like (the following is untested code):
passwd = None
i = 1
while i < len(sys.argv):
if sys.argv[i] == '--':
sys.argv.pop(i)
break
elif sys.argv[i] == '-p':
sys.argv.pop(i)
if i >= len(sys.argv):
help(1)
passwd = sys.argv.pop(i)
else:
i += 1
if passwd is None:
import getpass
passwd = getpass.getpass()
webrepl_cli.py
Outdated
@@ -14,7 +14,7 @@ | |||
# Treat this remote directory as a root for file transfers | |||
SANDBOX = "" | |||
#SANDBOX = "/tmp/webrepl/" | |||
DEBUG = 0 | |||
OUTPUT_LEVEL = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change this.
webrepl_cli.py
Outdated
print(msg) | ||
|
||
def infomsg(msg): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid
if 1:
print("op:%s, host:%s, port:%d, passwd:%s." % (op, host, port, passwd))
print(src_file, "->", dst_file)
is a kind of bad code. But if you insist to leave it, OK then. Or maybe we could add a parameter to debugmsg()
?
webrepl_cli.py
Outdated
print(" <host>:<remote_file> <local_file> - Copy remote file to local file") | ||
print(" <local_file> <host>:<remote_file> - Copy local file to remote file") | ||
print(" <host>:<remote_file> <local_file> [-p password] - Copy remote file to local file") | ||
print(" <local_file> <host>:<remote_file> [-p password] - Copy local file to remote file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's customary to put options before the mandatory positional args.
webrepl_cli.py
Outdated
if os.path.isdir(dst_file): | ||
basename = src_file.rsplit("/", 1)[-1] | ||
dst_file += "/" + basename | ||
infomsg("%s %s from %s:%d (passwd:%s) and save as %s" % | ||
(op, src_file, host, port, passwd, os.path.abspath(dst_file))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave the original messages as they were. It particular you don't want to print out the password!
OK, what do you think? |
@dpgeorge ping |
patch working as intended, this is a huge improvement to use webrepl in a shell script. |
@Himura2la : Instead of pop'ing values out of sys.args, it would be better to just parse it once and assign values to local vars. Because your approach doesn't scale if more options are added. But what really precluded your patch to be merged is that it contained unrelated changes. If you want to add a password option, the patch should contain the minimal changes to achieve it, and not a character more. Anyway, thanks for persistence, I cleaned up the patch and merged it. |
I don't want to enter password every time. I created run-scripts with the host and file and I need it to run quick.