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
60
UI Functional Testing
jasonamyers
1
110
Other Decks in Technology
See All in Technology
型情報を用いたLintでコード品質を向上させる
sansantech
PRO
2
140
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
160
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
140
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
190
最近のSfM手法まとめ - COLMAP / GLOMAPを中心に -
kwchrk
3
470
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
180
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
170
[Oracle TechNight#85] Oracle Autonomous Databaseを使ったAI活用入門
oracle4engineer
PRO
1
130
watsonx.ai Dojo #5 ファインチューニングとInstructLAB
oniak3ibm
PRO
0
190
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
18
5.6k
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
190
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
280
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
133
9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Become a Pro
speakerdeck
PRO
26
5k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
170
Mobile First: as difficult as doing things right
swwweet
222
9k
Embracing the Ebb and Flow
colly
84
4.5k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Code Reviewing Like a Champion
maltzj
521
39k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
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