-
-
Save CalfCrusher/219cffa060e9b40619b3f4ee190c43f1 to your computer and use it in GitHub Desktop.
Python Script Template with logging and arguments
This file contains hidden or 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
import sys | |
import os | |
import argparse | |
import getpass | |
import logging | |
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | |
logger = logging.getLogger('upload_bom') | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description=__doc__) | |
parser.add_argument('-u', '--user', dest='email', type=str, help='Username/Email used for login') | |
parser.add_argument('-p', '--production', dest='production', action='store_true', help='Example of boolean arg') | |
parser.add_argument('-o', '--option', dest='option', type=str, help='Example of str arg') | |
parser.add_argument('file', metavar='file', type=str, help='Example of a positional argument') | |
args = parser.parse_args() | |
logger.info('--------------') | |
# Never ask for a password in command-line. Manually ask for it here | |
password = getpass.getpass() | |
logger.info('Hello World!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment