鍍金池/ 問答/Python  Linux/ 如何使用python寫一個(gè)命令行工具?

如何使用python寫一個(gè)命令行工具?

類似 systemctl start myservice 后臺(tái)啟動(dòng)后,程序初始化后,就可以在linux界面輸入 myservice command arg.. 這樣來完成一些工作。希望了解以下大致的實(shí)現(xiàn)過程,以及能幫得上忙的模塊或者教程,我自己再去研究一下。
主要是想把現(xiàn)在零散的運(yùn)維工作匯集一下,能靈活得管理工作中使用的各個(gè)腳本、程序

回答
編輯回答
涼心人

http://python.jobbole.com/84769/
這個(gè)博文里講解的很詳細(xì),你可以參考一下

2017年10月12日 01:12
編輯回答
毀了心

prompt_toolkit # 強(qiáng)大的命令行交互
click # 命令行神器
cli_helpers # 強(qiáng)大的輸出更好看

結(jié)合以上三種的pg神器pgcli開源全python命令行交互 https://github.com/dbcli/pgcl...

2018年2月14日 09:57
編輯回答
失心人

可以使用谷歌出品的Fire構(gòu)建命令行/

github地址:https://github.com/google/pyt...
官方文檔介紹如下。

Python Fire is a library for creating command line interfaces (CLIs) from absolutely any Python object.
Python Fire is a simple way to create a CLI in Python.
Python Fire is a helpful tool for developing and debugging Python code.
Python Fire helps with exploring existing code or turning other people’s code into a CLI.
Python Fire makes transitioning between Bash and Python easier.
Python Fire makes using a Python REPL easier by setting up the REPL with the modules and variables you’ll need already imported and created.
2017年4月21日 06:24
編輯回答
笑忘初

搜索下python daemon就可以找到一堆。

如果想更普遍一點(diǎn)弄個(gè):
先開發(fā)個(gè)server端,開個(gè)命名管道等待cli client接入發(fā)送指令。
再開發(fā)個(gè)簡(jiǎn)單的cli client把指令通過命名管道發(fā)給server。命令解析用argpare就可以了

2017年1月8日 21:27