Skip to content

Instantly share code, notes, and snippets.

@zhester
Created May 14, 2013 13:20
Show Gist options
  • Save zhester/5575802 to your computer and use it in GitHub Desktop.
Save zhester/5575802 to your computer and use it in GitHub Desktop.
Python Shell Script
#!/usr/bin/env python
"""
A Shell Script
"""
__version__ = '0.0.0'
#=============================================================================
def main( argv ):
"""
Script execution entry point
@param argv Arguments passed to the script
@return Exit code (0 = success)
"""
# imports when using this as a script
import argparse
# create and configure an argument parser
parser = argparse.ArgumentParser(
description = 'A Shell Script',
add_help = False
)
parser.add_argument(
'-h',
'--help',
default = False,
help = 'Display this help message and exit.',
action = 'help'
)
parser.add_argument(
'-v',
'--version',
default = False,
help = 'Display script version and exit.',
action = 'version',
version = __version__
)
# parse the arguments
args = parser.parse_args( argv[ 1 : ] )
# check args.* for script execution here
# return success
return 0
#=============================================================================
if __name__ == "__main__":
import sys
sys.exit( main( sys.argv ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment