Skip to content

Instantly share code, notes, and snippets.

@rjfonseca
Forked from opie4624/commandline.py
Last active December 20, 2015 19:38
Show Gist options
  • Save rjfonseca/6184559 to your computer and use it in GitHub Desktop.
Save rjfonseca/6184559 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright [yyyy] [name of copyright owner]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import argparse
import logging
def main(args, loglevel):
logging.basicConfig(format="%(levelname)s: %(message)s", level=loglevel)
# TODO Replace this with your actual code.
print "Hello there."
logging.info("You passed an argument.")
logging.debug("Your Argument: %s" % args.argument)
return 0
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description = "Does a thing to some stuff.",
epilog = "As an alternative to the commandline, params can be placed in a file, one per line, and specified on the commandline like '%(prog)s @params.conf'.",
fromfile_prefix_chars = '@' )
# TODO Specify your real parameters here.
parser.add_argument(
"argument",
help = "pass ARG to the program",
metavar = "ARG")
parser.add_argument(
"-v",
"--verbose",
help="increase output verbosity",
action="store_true")
args = parser.parse_args()
if args.verbose:
loglevel = logging.DEBUG
else:
loglevel = logging.INFO
sys.exit(main(args, loglevel))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment