Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building CLIs that Click
Search
Jason Myers
May 29, 2015
Technology
0
43
Building CLIs that Click
PyNash presentation on building better CLIs
Jason Myers
May 29, 2015
Tweet
Share
More Decks by Jason Myers
See All by Jason Myers
Introduction to Pandas
jasonamyers
2
200
Generating Power with Yield
jasonamyers
1
180
Introduction to SQLAlchemy and Alembic
jasonamyers
4
1k
Data Networking for Developers
jasonamyers
0
130
Diabetes and Me
jasonamyers
0
57
UI Functional Testing
jasonamyers
1
110
Other Decks in Technology
See All in Technology
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
210
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
320
強いチームと開発生産性
onk
PRO
36
12k
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
170
Engineer Career Talk
lycorp_recruit_jp
0
200
TypeScript、上達の瞬間
sadnessojisan
48
14k
電話を切らさない技術 電話自動応答サービスを支える フロントエンド
barometrica
1
170
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
330
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
130
Next.jsとNuxtが混在? iframeでなんとかする!
ypresto
2
450
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Writing Fast Ruby
sferik
627
61k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
The Invisible Side of Design
smashingmag
298
50k
Designing the Hi-DPI Web
ddemaree
280
34k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
For a Future-Friendly Web
brad_frost
175
9.4k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Designing for humans not robots
tammielis
250
25k
Why Our Code Smells
bkeepers
PRO
334
57k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Transcript
BUILDING CLIS THAT CLICK Created by / Jason A Myers
@jasonamyers
BUILDING GOOD COMMAND LINE APPLICATIONS IS HARD
IMPORTANT PARTS NAME ARGUMENT PARSING AND VALIDATION * HELP GENERATION
* COMMAND STRUCTURE * AUTOCOMPLETION NICE OUTPUT PACKAGING *
ARGUMENTS AND HELP
THREE DIFFERENT PARSERS IN THE STDLIB getopt optparse argparse
I MEAN ARGPARSE IS THE NEW HOTNESS???
SERIOUSLY WHO KNOWS HOW *!@%PARSE WORKS ANYWAY
NO REALLY HAVE YOU LOOKED AT THE DOCS...
None
SERIOUSLY BRAIN CELLS EXPLODE
HOW BAD IS IT? docopt Plac Cliff Clint
import sys if __name__ == "__main__": main(sys.argv)
None
DEMO
LOGGING
GOOD LOGGING MESSAGES Time Module Level Parseable Messages
2015-05-28 09:25:18,711 - complex.logger - DEBUG - Creating composit e:
cookies 2015-05-28 09:25:18,711 - complex.logger - DEBUG - Created composite : cookies
JAM'S LOGGING STYLE
import logging logger = logging.getLogger(__name__) logger.setLevel(logging.ERROR)
file_log_handler = logging.FileHandler('complex-cli.log') logger.addHandler(file_log_handler) stderr_log_handler = logging.StreamHandler() logger.addHandler(stderr_log_handler)
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)
PACKAGING
FIND OUR MODULE from setuptools import setup, find_packages setup( name='complex',
version='0.1.2', packages=find_packages(), include_package_data=True,
install_requires=[ 'Click==3.3', ],
description='A description', classifiers=[ 'License :: OSI Approved :: BSD License',
'Programming Language :: Python', 'Programming Language :: Python :: 3', ],
entry_points=''' [console_scripts] complex=complex.command:cli ''' )
COMPLEX DEMO
None
QUESTIONS @JASONAMYERS