Skip to content

Instantly share code, notes, and snippets.

@jiankaiwang
Created April 22, 2018 08:14
Show Gist options
  • Select an option

  • Save jiankaiwang/5de97e0fa5f0b1762ef1ee89adb85df9 to your computer and use it in GitHub Desktop.

Select an option

Save jiankaiwang/5de97e0fa5f0b1762ef1ee89adb85df9 to your computer and use it in GitHub Desktop.
basic operations of parameters in CLI over Python
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 22 16:04:40 2018
@description: Basic Operation in CLI
@author: JianKai Wang
"""
# coding: utf-8
import sys
import getopt
import logging
# help message
def helpMessgae():
print("""Usage: python Basic_CLI_Parameters.py [options]
[options]
-o (necessary)
-p (necessary)
-h, --help the help message
""")
# parse opts
def parseOpts(get_opts):
return(dict((k,v) for k,v in get_opts))
# main entry
logging.basicConfig(level=logging.WARNING)
opts, args = getopt.getopt(sys.argv[1:], "fho:p:", ["help"])
opts = parseOpts(opts)
if len(opts) < 1:
logging.debug("opts < 1")
helpMessgae()
elif '--help' in opts.keys() or '-h' in opts.keys():
logging.debug("opts exists help")
helpMessgae()
else:
# the further operations
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment