Skip to content

Instantly share code, notes, and snippets.

@hmm01i
Created May 19, 2017 17:45
Show Gist options
  • Save hmm01i/79e340ad5557992ebf0971646b3764d9 to your computer and use it in GitHub Desktop.
Save hmm01i/79e340ad5557992ebf0971646b3764d9 to your computer and use it in GitHub Desktop.
snippet example of using optparse
# just a short example of using optparse
import getpass
import optparse
# def parseCmdArgs():
cmdOpts = optparse.OptionParser(usage = '%prog [options]')
cmdOpts.add_option('-i', dest = 'ipaddr', help = 'IP address of CIMC')
cmdOpts.add_option('-u', dest = 'user', help = 'Username')
cmdOpts.add_option('-p', dest = 'passwd', help = 'Password (Optional. If not provided you will be prompted.)')
cmdOpts.add_option('-l', action = 'store_true', dest = 'list', help = 'Just query running firmware.')
cmdOpts.add_option('-v', action = 'store_true', dest = 'verbose', help = 'Verbose output')
cmdOpts.add_option('-n', action = 'store_true', dest = 'dry', help = 'Dry run')
(opts, args) = cmdOpts.parse_args()
def getpassword(prompt = "CIMC Password: "):
return getpass.unix_getpass(prompt)%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment