SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
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 (fish)
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()
fuzzyfinder
from fuzzyfinder import fuzzyfinder
suggest = fuzzyfinder(
'makemsg',
['makemessages', 'django', ‘compilemessages']
)
print(list(suggest))
Summary
• 做個好 CLI 讓⼤大家開⼼心點

• python-prompt-toolkit, click, pygements, fuzzyfinder

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

• 請寄給 excusemejoe@gmail.com

Contenu connexe

Similaire à Power UP your CLI

大家應該都要會的工具 Git 從放棄到會用1-基礎篇
大家應該都要會的工具 Git   從放棄到會用1-基礎篇大家應該都要會的工具 Git   從放棄到會用1-基礎篇
大家應該都要會的工具 Git 從放棄到會用1-基礎篇Alan Tsai
 
電子內容管理 使用Git 與 github 1
電子內容管理   使用Git 與 github 1電子內容管理   使用Git 與 github 1
電子內容管理 使用Git 與 github 1Alan Tsai
 
Jenkins x GitLab CI
Jenkins x GitLab CIJenkins x GitLab CI
Jenkins x GitLab CIYihsuan Chen
 
Git and Github basic with SourceTree
Git and Github basic with SourceTreeGit and Github basic with SourceTree
Git and Github basic with SourceTreeChu-Siang Lai
 
從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 Taiwan
從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 Taiwan從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 Taiwan
從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 TaiwanAlan Tsai
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作奕浦 郭
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報Bachue Zhou
 
[students AI workshop] Pytorch
[students AI workshop]  Pytorch[students AI workshop]  Pytorch
[students AI workshop] PytorchTzu-Wei Huang
 
How to integrate GitLab CICD into B2B service
How to integrate GitLab CICD into B2B serviceHow to integrate GitLab CICD into B2B service
How to integrate GitLab CICD into B2B serviceAlex Su
 
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2Alan Tsai
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用勇浩 赖
 
不妥協的河蟹之道
不妥協的河蟹之道不妥協的河蟹之道
不妥協的河蟹之道Ken Kuan
 
大獅子與小獅子的分享
大獅子與小獅子的分享大獅子與小獅子的分享
大獅子與小獅子的分享jo lin
 
[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204CAVEDU Education
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIChu-Siang Lai
 

Similaire à Power UP your CLI (20)

大家應該都要會的工具 Git 從放棄到會用1-基礎篇
大家應該都要會的工具 Git   從放棄到會用1-基礎篇大家應該都要會的工具 Git   從放棄到會用1-基礎篇
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
 
電子內容管理 使用Git 與 github 1
電子內容管理   使用Git 與 github 1電子內容管理   使用Git 與 github 1
電子內容管理 使用Git 與 github 1
 
Jenkins x GitLab CI
Jenkins x GitLab CIJenkins x GitLab CI
Jenkins x GitLab CI
 
Git and Github basic with SourceTree
Git and Github basic with SourceTreeGit and Github basic with SourceTree
Git and Github basic with SourceTree
 
從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 Taiwan
從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 Taiwan從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 Taiwan
從 GitHub Copilot 到 Enterprise Copilot:打造符合企業需求的智能開發助手之路 | .NET Conf 2023 Taiwan
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
 
[students AI workshop] Pytorch
[students AI workshop]  Pytorch[students AI workshop]  Pytorch
[students AI workshop] Pytorch
 
Go
GoGo
Go
 
Go
GoGo
Go
 
How to integrate GitLab CICD into B2B service
How to integrate GitLab CICD into B2B serviceHow to integrate GitLab CICD into B2B service
How to integrate GitLab CICD into B2B service
 
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用
 
不妥協的河蟹之道
不妥協的河蟹之道不妥協的河蟹之道
不妥協的河蟹之道
 
大獅子與小獅子的分享
大獅子與小獅子的分享大獅子與小獅子的分享
大獅子與小獅子的分享
 
[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204
 
Build Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratchBuild Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratch
 
Cocoa on Rails 4th
Cocoa on Rails 4thCocoa on Rails 4th
Cocoa on Rails 4th
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CI
 

Plus de Andy Dai

Grpc + python.key
Grpc + python.keyGrpc + python.key
Grpc + python.keyAndy Dai
 
該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?Andy Dai
 
Search search search
Search search searchSearch search search
Search search searchAndy Dai
 
Django channels
Django channelsDjango channels
Django channelsAndy Dai
 
Django Third party packages
Django Third party packagesDjango Third party packages
Django Third party packagesAndy Dai
 
Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirtyAndy Dai
 
總之來講講 Search
總之來講講 Search總之來講講 Search
總之來講講 SearchAndy Dai
 
Python web meetup 11 18
Python web meetup 11 18Python web meetup 11 18
Python web meetup 11 18Andy Dai
 
Django in heavy load environment
Django in heavy load environmentDjango in heavy load environment
Django in heavy load environmentAndy Dai
 
電腦不只會幫你選土豆,還會幫你選新聞
電腦不只會幫你選土豆,還會幫你選新聞電腦不只會幫你選土豆,還會幫你選新聞
電腦不只會幫你選土豆,還會幫你選新聞Andy Dai
 
用 Python 打造你自己的 summly
用 Python 打造你自己的 summly用 Python 打造你自己的 summly
用 Python 打造你自己的 summlyAndy Dai
 
Tradeoffs of replacing core components
Tradeoffs of replacing core componentsTradeoffs of replacing core components
Tradeoffs of replacing core componentsAndy Dai
 
ElastiCache
ElastiCacheElastiCache
ElastiCacheAndy Dai
 
Django deploy
Django deployDjango deploy
Django deployAndy Dai
 
Build your own trello witihin 100 LOC (with Meteor)
Build your own trello witihin 100 LOC (with Meteor)Build your own trello witihin 100 LOC (with Meteor)
Build your own trello witihin 100 LOC (with Meteor)Andy Dai
 
Boost your django admin with Grappelli
Boost your django admin with GrappelliBoost your django admin with Grappelli
Boost your django admin with GrappelliAndy Dai
 

Plus de Andy Dai (17)

Grpc + python.key
Grpc + python.keyGrpc + python.key
Grpc + python.key
 
該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?
 
Search search search
Search search searchSearch search search
Search search search
 
Django channels
Django channelsDjango channels
Django channels
 
Django Third party packages
Django Third party packagesDjango Third party packages
Django Third party packages
 
Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirty
 
總之來講講 Search
總之來講講 Search總之來講講 Search
總之來講講 Search
 
Python web meetup 11 18
Python web meetup 11 18Python web meetup 11 18
Python web meetup 11 18
 
Django in heavy load environment
Django in heavy load environmentDjango in heavy load environment
Django in heavy load environment
 
電腦不只會幫你選土豆,還會幫你選新聞
電腦不只會幫你選土豆,還會幫你選新聞電腦不只會幫你選土豆,還會幫你選新聞
電腦不只會幫你選土豆,還會幫你選新聞
 
用 Python 打造你自己的 summly
用 Python 打造你自己的 summly用 Python 打造你自己的 summly
用 Python 打造你自己的 summly
 
Tradeoffs of replacing core components
Tradeoffs of replacing core componentsTradeoffs of replacing core components
Tradeoffs of replacing core components
 
ElastiCache
ElastiCacheElastiCache
ElastiCache
 
Dynamo db
Dynamo dbDynamo db
Dynamo db
 
Django deploy
Django deployDjango deploy
Django deploy
 
Build your own trello witihin 100 LOC (with Meteor)
Build your own trello witihin 100 LOC (with Meteor)Build your own trello witihin 100 LOC (with Meteor)
Build your own trello witihin 100 LOC (with Meteor)
 
Boost your django admin with Grappelli
Boost your django admin with GrappelliBoost your django admin with Grappelli
Boost your django admin with Grappelli
 

Power UP your CLI