狠狠撸

狠狠撸Share a Scribd company logo
Power UP Your CLI
Andy Dai

daikeren@gmail.com
?自我介紹
? Andy

? Django, Python, DevOps 都略略懂略略懂

? 擔任無業遊?民中
緣起
? kube-shell

? pgcli
CLI
? 新?手惡惡夢

? 功能都藏起來來了了

? 有 Help 可以?用(?)

? —help(?) -h(?) help(?)

? ?一堆指令根本記不起來來
git
django manage.py
? 下?面哪個是正確的選項?

? make_message

? makemessage

? makemessages

? make_messages
為了了解決這些問題
? alias

? zsh plugins

? …
CLI 能不能做得更更好?
?一個好的 CLI 會有哪些
功能?
GUI
Auto Complete (tab)
Auto Suggestion (?sh)
History (上下鍵)
Syntax Coloring
(關鍵字)
要實作這些好像
有點難...
pip install prompt_toolkit
直接來來 DEMO
from prompt_toolkit import prompt
from prompt_toolkit.history import FileHistory
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.contrib.completers import WordCompleter
from pygments.lexers.sql import SqlLexer
completer = WordCompleter(
['SELECT', 'FROM', 'WHERE', 'IN'],
ignore_case=True)
while 1:
text = prompt('> ',
history=FileHistory('history'),
auto_suggest=AutoSuggestFromHistory(),
completer=completer,
lexer=SqlLexer,
vi_mode=True,
)
print(text)
要做個好 CLI 你可能還
需要這些
click
import click
@click.command()
@click.option('--a', help='a', type=click.INT)
@click.option('--b', help='b', type=click.INT)
def add(a, b):
click.echo(a+b)
if __name__ == '__main__':
add()
fuzzy?nder
from fuzzyfinder import fuzzyfinder
suggest = fuzzyfinder(
'makemsg',
['makemessages', 'django', ‘compilemessages']
)
print(list(suggest))
Summary
? 做個好 CLI 讓?大家開?心點

? python-prompt-toolkit, click, pygements, fuzzy?nder

? https://github.com/jonathanslenders/python-prompt-
toolkit/tree/master/examples
?工商服務
? UmboCV CV Team 徵求 Backend Engineer 中

? 請寄給 excusemejoe@gmail.com

More Related Content

More from Andy Dai (9)

PDF
Django in heavy load environment
Andy Dai
?
PDF
电脑不只会帮你选土豆,还会帮你选新闻
Andy Dai
?
PDF
用 Python 打造你自己的 summly
Andy Dai
?
PDF
Tradeoffs of replacing core components
Andy Dai
?
PDF
ElastiCache
Andy Dai
?
PDF
Dynamo db
Andy Dai
?
PDF
Django deploy
Andy Dai
?
PDF
Build your own trello witihin 100 LOC (with Meteor)
Andy Dai
?
PDF
Boost your django admin with Grappelli
Andy Dai
?
Django in heavy load environment
Andy Dai
?
电脑不只会帮你选土豆,还会帮你选新闻
Andy Dai
?
用 Python 打造你自己的 summly
Andy Dai
?
Tradeoffs of replacing core components
Andy Dai
?
ElastiCache
Andy Dai
?
Dynamo db
Andy Dai
?
Django deploy
Andy Dai
?
Build your own trello witihin 100 LOC (with Meteor)
Andy Dai
?
Boost your django admin with Grappelli
Andy Dai
?

Power UP your CLI