Created
February 19, 2017 19:55
-
-
Save grzhan/77222b1a737e1ad9cb00b28e025ec1e2 to your computer and use it in GitHub Desktop.
An auto-login script for npm command line (powered by pexpect)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import sys | |
from pexpect import spawn, EOF | |
def main(): | |
user_table = { | |
'username': ('username', 'password', 'email') | |
# ... | |
} | |
if len(sys.argv) < 2: | |
print('Usage: npm-login username') | |
return | |
key = sys.argv[1] | |
if key not in user_table: | |
print('User "{}" not found, below users are accepted:'.format(key)) | |
print(user_table.keys()) | |
return | |
username, password, email = user_table[key] | |
child = spawn('npm adduser') | |
child.logfile_read = sys.stdout | |
child.expect('Username:') | |
child.sendline(username) | |
child.expect('Password:') | |
child.sendline(password) | |
child.expect('Email:*') | |
child.sendline(email) | |
child.expect('Logged in*') | |
child.expect(EOF) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment