Added password prompt #16

Merged
Spirit-act merged 2 commits from feature-password-prompt into master 5 years ago
Spirit-act commented 5 years ago (Migrated from github.com)
Owner

Resolves #15

Changes:

  • Remove the required option on the "password" command line argument
  • Added check for None or empty "password" command line argument
  • Added option to prompt for a password if command line argument is empty or None
Resolves #15 Changes: - Remove the required option on the "password" command line argument - Added check for None or empty "password" command line argument - Added option to prompt for a password if command line argument is empty or None
connorskees (Migrated from github.com) reviewed 5 years ago
connorskees (Migrated from github.com) commented 5 years ago
Owner

I think you could make this declaration cleaner by just having it as

password = args.password or input('Enter your password: ')
I think you could make this declaration cleaner by just having it as ``` password = args.password or input('Enter your password: ') ```
Spirit-act (Migrated from github.com) reviewed 5 years ago
Spirit-act (Migrated from github.com) commented 5 years ago
Poster
Owner

There is a requirement for a check if the arg is empty.
I could have written it as a oneliner, but I think for beginners it is more understandable.

args_user_password = args.password if args.password is not None or not args.password else input('Enter your password: ')

There is a requirement for a check if the arg is empty. I could have written it as a oneliner, but I think for beginners it is more understandable. `args_user_password = args.password if args.password is not None or not args.password else input('Enter your password: ')`
connorskees (Migrated from github.com) reviewed 5 years ago
connorskees (Migrated from github.com) commented 5 years ago
Owner

args.password is not None or not args.password
Wouldn't this always be true? Not sure if I'm just missing something lol

```args.password is not None or not args.password``` Wouldn't this always be true? Not sure if I'm just missing something lol
weskerfoot (Migrated from github.com) reviewed 5 years ago
weskerfoot (Migrated from github.com) commented 5 years ago
Owner

I'd prefer either:
args.password if args.password else input('Enter your password: ') or args.password or input('Enter your password: ')

Generally it's a good idea in Python to rely on the fact that certain values are "falsey" instead of checking for explicit values like None or False.

Don't want to bikeshed too hard though. You could make it multiline instead of a oneliner too and it doesn't make a huge difference to me.

I'd prefer either: `args.password if args.password else input('Enter your password: ')` or `args.password or input('Enter your password: ')` Generally it's a good idea in Python to rely on the fact that certain values are "falsey" instead of checking for explicit values like None or False. Don't want to bikeshed too hard though. You could make it multiline instead of a oneliner too and it doesn't make a huge difference to me.
Spirit-act (Migrated from github.com) reviewed 5 years ago
Spirit-act (Migrated from github.com) commented 5 years ago
Poster
Owner

But if I use args.password or input('Enter your password: '), the "empty" would not be caught. At least in my tests.

But if I use `args.password or input('Enter your password: ')`, the "empty" would not be caught. At least in my tests.
connorskees (Migrated from github.com) reviewed 5 years ago
connorskees (Migrated from github.com) commented 5 years ago
Owner

@Spirit-act I'm not sure what you mean. I believe empty strings '' evaluate to false?

@Spirit-act I'm not sure what you mean. I believe empty strings `''` evaluate to false?
weskerfoot (Migrated from github.com) reviewed 5 years ago
weskerfoot (Migrated from github.com) commented 5 years ago
Owner

You can also do args.password.strip() if you're worried about whitespace, and it will evaluate to False if the string is made up of whitespace.

You can also do `args.password.strip()` if you're worried about whitespace, and it will evaluate to `False` if the string is made up of whitespace.
Spirit-act (Migrated from github.com) reviewed 5 years ago
Spirit-act (Migrated from github.com) commented 5 years ago
Poster
Owner

unfortunately not, my tests:

$ x = None
$ y = " "
$ a = x or input(': ')
: b
$ a = y or input(': ')
$

unfortunately not, my tests: > $ x = None $ y = " " $ a = x or input(': ') : b $ a = y or input(': ') $
weskerfoot (Migrated from github.com) reviewed 5 years ago
weskerfoot (Migrated from github.com) commented 5 years ago
Owner
>>> x = ""
>>> foo = x or input("blah: ")
blah: dsfsdfdsf
``` >>> x = "" >>> foo = x or input("blah: ") blah: dsfsdfdsf ```
Spirit-act (Migrated from github.com) reviewed 5 years ago
Spirit-act (Migrated from github.com) commented 5 years ago
Poster
Owner

I want to catch your workaround with space:

A workaround at the moment is to prefix your invocation of the command with a space which will cause bash (and maybe other shells?) to not log it in your history.

But if you want, I'll change it to your preferences.

I want to catch your workaround with space: > A workaround at the moment is to prefix your invocation of the command with a space which will cause bash (and maybe other shells?) to not log it in your history. But if you want, I'll change it to your preferences.
weskerfoot (Migrated from github.com) reviewed 5 years ago
weskerfoot (Migrated from github.com) commented 5 years ago
Owner

I don't think we need to worry about that getting caught by this. It's specific to bash and wouldn't be caught by this.

I don't think we need to worry about that getting caught by this. It's specific to bash and wouldn't be caught by this.
Spirit-act (Migrated from github.com) reviewed 5 years ago
Spirit-act (Migrated from github.com) left a comment
  • Changed Code
  • Pushed new code
Spirit-act (Migrated from github.com) commented 5 years ago
Poster
Owner

Ok, I have changed the code.

Ok, I have changed the code.
weskerfoot commented 5 years ago (Migrated from github.com)
Owner
* Changed Code

* Pushed new code

I'll give it a test run when I get a chance :) Thanks for the contribution

> * Changed Code > > * Pushed new code I'll give it a test run when I get a chance :) Thanks for the contribution
The pull request has been merged as 748bd851e7.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.