Top Banner
BUILDING CLIS THAT CLICK Created by / Jason A Myers @jasonamyers
29

Building CLIs that Click

Aug 04, 2015

Download

Technology

Jason Myers
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building CLIs that Click

BUILDING CLIS THAT

CLICKCreated by / Jason A Myers @jasonamyers

Page 2: Building CLIs that Click

BUILDING GOOD COMMAND LINEAPPLICATIONS IS HARD

Page 3: Building CLIs that Click

IMPORTANT PARTSNAME

ARGUMENT PARSING AND VALIDATION *HELP GENERATION *

COMMAND STRUCTURE *AUTOCOMPLETION

NICE OUTPUTPACKAGING *

Page 4: Building CLIs that Click

ARGUMENTS AND HELP

Page 5: Building CLIs that Click

THREE DIFFERENT PARSERS IN THE

STDLIB

getoptoptparseargparse

Page 6: Building CLIs that Click

I MEAN ARGPARSE IS THE NEW HOTNESS???

Page 7: Building CLIs that Click

SERIOUSLY WHO KNOWS HOW*!@%PARSE WORKS ANYWAY

Page 8: Building CLIs that Click

NO REALLY HAVE YOU LOOKED ATTHE DOCS...

Page 9: Building CLIs that Click
Page 10: Building CLIs that Click

SERIOUSLY BRAIN CELLS EXPLODE

Page 11: Building CLIs that Click

HOW BAD IS IT?docoptPlacCliffClint

Page 12: Building CLIs that Click

import sysif __name__ == "__main__": main(sys.argv)

Page 13: Building CLIs that Click
Page 14: Building CLIs that Click

DEMO

Page 15: Building CLIs that Click

LOGGING

Page 16: Building CLIs that Click

GOOD LOGGING MESSAGES

TimeModuleLevelParseable Messages

Page 17: Building CLIs that Click

2015-05-28 09:25:18,711 - complex.logger - DEBUG - Creating composite: cookies2015-05-28 09:25:18,711 - complex.logger - DEBUG - Created composite: cookies

Page 18: Building CLIs that Click

JAM'S LOGGING STYLE

Page 19: Building CLIs that Click

import logging

logger = logging.getLogger(__name__)

logger.setLevel(logging.ERROR)

Page 20: Building CLIs that Click

file_log_handler = logging.FileHandler('complex-cli.log')

logger.addHandler(file_log_handler)

stderr_log_handler = logging.StreamHandler()

logger.addHandler(stderr_log_handler)

Page 21: Building CLIs that Click

format_string = '%(asctime)s - %(name)s - ' \ '%(levelname)s - %(message)s'formatter = logging.Formatter(format_string)file_log_handler.setFormatter(formatter)stderr_log_handler.setFormatter(formatter)

Page 22: Building CLIs that Click

PACKAGING

Page 23: Building CLIs that Click

FIND OUR MODULE

from setuptools import setup, find_packages

setup( name='complex', version='0.1.2', packages=find_packages(), include_package_data=True,

Page 24: Building CLIs that Click

install_requires=[ 'Click==3.3', ],

Page 25: Building CLIs that Click

description='A description',

classifiers=[

'License :: OSI Approved :: BSD License',

'Programming Language :: Python',

'Programming Language :: Python :: 3',

],

Page 26: Building CLIs that Click

entry_points=''' [console_scripts] complex=complex.command:cli ''')

Page 27: Building CLIs that Click

COMPLEX DEMO

Page 28: Building CLIs that Click
Page 29: Building CLIs that Click

QUESTIONS

@JASONAMYERS