# MILC - An Opinionated Batteries-Included Python 3 CLI Framework
MILC is a framework for writing CLI applications in Python 3.6+. It gives you
all the features users expect from a modern CLI tool out of the box:
* CLI Argument Parsing, with or without subcommands
* Automatic tab-completion support through [argcomplete](https://github.com/kislyuk/argcomplete)
* Configuration file which can be overridden by CLI options
* ANSI color support- even on Windows- with [colorama](https://github.com/tartley/colorama)
* Logging to stderr and/or a file, with ANSI colors
* Easy method for printing to stdout with ANSI colors
* Labeling log output with colored emoji to easily distinguish message types
* Thread safety
* More than 60 built-in [spinners](https://github.com/manrajgrover/py-spinners) with the ability to add your own
# Installation
MILC is available on pypi, you can use pip to install it:
python3 -m pip install milc
# ChangeLog and Breaking Changes
MILC follows [Semantic Versioning](https://semver.org/). You can view the [full changelog](https://github.com/clueboard/milc/blob/master/CHANGELOG.rst), or you can see a list of why we made major or minor releases on the [Breaking Changes](https://milc.clueboard.co/#/breaking_changes) page.
# Documentation
Full documentation is on the web: <https://milc.clueboard.co/>
## Reporting Bugs and Requesting Features
Please let us know about any bugs and/or feature requests you have: <https://github.com/clueboard/milc/issues>
## Short Example
```python
from milc import cli
@cli.argument('-c', '--comma', arg_only=True, action='store_boolean', default=True, help='comma in output')
@cli.argument('-n', '--name', default='World', help='Name to greet')
@cli.entrypoint('My useful CLI tool.')
def main(cli):
comma = ',' if cli.args.comma else ''
cli.log.info('Hello%s %s!', comma, cli.config.general.name)
if __name__ == '__main__':
cli.run()
```
### Output
```
$ ./hello
ℹ Hello, World!
$ ./hello --no-unicode
INFO Hello, World!
$ ./hello --no-comma
ℹ Hello World!
$ ./hello -h
usage: hello [-h] [-V] [-v] [--datetime-fmt GENERAL_DATETIME_FMT]
[--log-fmt GENERAL_LOG_FMT] [--log-file-fmt GENERAL_LOG_FILE_FMT]
[--log-file GENERAL_LOG_FILE] [--color] [--no-color]
[--config-file GENERAL_CONFIG_FILE] [--save-config]
[-n GENERAL_NAME] [-c] [--no-comma]
Greet a user.
optional arguments:
-h, --help show this help message and exit
-V, --version Display the version and exit
-v, --verbose Make the logging more verbose
--datetime-fmt GENERAL_DATETIME_FMT
Format string for datetimes
--log-fmt GENERAL_LOG_FMT
Format string for printed log output
--log-file-fmt GENERAL_LOG_FILE_FMT
Format string for log file.
--log-file GENERAL_LOG_FILE
File to write log messages to
--color Enable color in output
--no-color Disable color in output
--config-file GENERAL_CONFIG_FILE
The config file to read and/or write
--save-config Save the running configuration to the config file
-n GENERAL_NAME, --name GENERAL_NAME
Name to greet
-c, --comma Enable comma in output
--no-comma Disable comma in output
```
# Why MILC?
Because life is too short to integrate this stuff yourself, and writing
good CLIs with comprehensive functionality is harder than it needs to be.
Most of the other CLI frameworks are missing a piece of the puzzle. Maybe
they have argument parsing but no config file story. Maybe they have a
good story around arguments and config but don't handle logging at all.
You know that you're doing the same integration work that almost everyone
else is doing in their own app. Why do we duplicate so much effort?
MILC is my answer to that. It implements a common set of CLI tools that
pretty much every project I have ever worked on either needed or would
have benefited from. Included in MILC are answers to problems you didn't
know you have:
* Config file saving and parsing
* Automatically overriding config options with CLI arguments
* Automatic verbose (-v) support
* Automatic log support
* Built-in flags for formatting log messages and log date formats
* Support for boolean arguments (define --foo and get --no-foo for free)
* Battle tested and used by hundreds of users every single day
You may not use all of these features yourself, but you will have users
who are very glad these options are available when they need them.
# Contributing
Contributions are welcome! You don't need to open an issue first, if
you've developed a new feature or fixed a bug in MILC simply open
a PR and we'll review it.
Please follow this checklist before submitting a PR:
* [ ] Format your code: `yapf -i -r .`
* [ ] Generate docs: `./generate_docs`
* [ ] Add any new doc files to the `nav` section of `mkdocs.yml`
* [ ] Run tests: `./ci_tests`
# FAQ
## What does MILC stand for?
MILC was originally the CLI Context Manager, or CLI Manager, but CLICM was too close to [click](https://click.palletsprojects.com/) and CLIM was already taken on PyPi. Reversing CLIM gave me a name I liked and had opportunities for puns, so I went with it.
## Why decorators instead of parsing function signatures?
Because I believe in writing good CLI tools.
Before writing MILC I saw variations of the same story over and over. "I
started with {Click,Docopt,Whatever} but after a while I ended up just
going back to argparse." In pretty much every case as the complexity of
their program grew they needed to do things argparse made easy and their
framework made hard.
MILC attempts to solve this by embracing the complexity of argparse. It
handles the drudgery of setting up argparse for you, but gives you an
elegant means to control that complexity when you need to. When your
CLI framework relies on parsing function signatures you are necessarily
limited in what you can do. Function annotations make this a little
better but they are not a full solution to the problem.
If you care about writing good CLI tools (and I hope you do) you will want
more control over the behavior of your program than Click or Docopt give you.
## Why Not Some Other CLI Framework Instead?
Whenever you release a new framework the first question you'll be asked is
why you didn't just use one of the existing options instead.
As I surveyed the other tools I found that most of them only solve part of
the problem, not the whole problem. Those that solve the whole problem are
very hard to use or get started with, or are otherwise very heavyweight. I
wanted a comprehensive framework that was easy to get started with.
If you'd like to see how MILC compares to other tools see
[COMPARISONS.md](COMPARISONS.md).
没有合适的资源?快使用搜索试试~ 我知道了~
内置电池的Python3CLI框架_Python_Shell_下载.zip
共90个文件
md:26个
py:26个
yml:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 136 浏览量
2023-04-04
22:55:11
上传
评论
收藏 292KB ZIP 举报
温馨提示
内置电池的Python3CLI框架_Python_Shell_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
内置电池的Python3CLI框架_Python_Shell_下载.zip (90个子文件)
milc-master
.gitchangelog.rc 10KB
.editorconfig 409B
spinner 2KB
serve_docs 982B
generate_docs 2KB
CHANGELOG.rst 14KB
milc
__init__.py 2KB
_in_argv.py 670B
configuration.py 5KB
ansi.py 2KB
subcommand
__init__.py 0B
config.py 4KB
_sparkline.py 4KB
attrdict.py 1KB
emoji.py 822B
questions.py 8KB
milc.py 30KB
setup.py 2KB
.github
workflows
ci.yml 1KB
codeql-analysis.yml 3KB
devel_docs.yml 1005B
stale.yml 551B
python-publish.yml 2KB
LICENSE 1KB
tests
test_configuration.py 1011B
test_script_config_source.py 444B
__init__.py 0B
test_script_hello.py 4KB
test_script_questions.py 1KB
test_script_password.py 1KB
test_script_example.py 5KB
test_configuration_Configuration.py 2KB
common.py 793B
test___init__.py 586B
test_script_sparkline.py 336B
test_attrdict.py 2KB
test_ansi.py 629B
test_sparkline.py 2KB
.yapfignore 10B
sparkline 739B
nose2.cfg 53B
passwd_confirm 364B
spinner_qmk 885B
milc-color 1KB
release_docs 394B
questions 847B
docs
stylesheets
milc.css 113B
ANSI.md 2KB
configuration.md 3KB
subprocesses.md 3KB
breaking_changes.md 2KB
.nojekyll 0B
api__sparkline.md 3KB
api_emoji.md 505B
sparklines.md 2KB
spinners.md 2KB
installation.md 120B
subcommand_config.md 3KB
api_subcommand_config.md 2KB
api__in_argv.md 37B
threading.md 890B
metadata.md 1KB
tutorial.md 8KB
argument_parsing.md 2KB
logging.md 2KB
api_questions.md 4KB
api_attrdict.md 725B
api_milc.md 8KB
api_configuration.md 2KB
argcomplete.md 2KB
images
tutorial_example1.png 46KB
tutorial_example2.png 10KB
tutorial_example4.png 23KB
tutorial_example3.png 141KB
api_ansi.md 370B
README.md 3KB
config_source 367B
release 1KB
ci_tests 1KB
requirements-dev.txt 113B
requirements-release.txt 101B
requirements.txt 5B
COMPARISONS.md 6KB
.gitignore 81B
setup.cfg 2KB
example 2KB
README.md 7KB
mkdocs.yml 2KB
passwd_complexity 1KB
hello 638B
共 90 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- n.cpp
- jdk-8u411-windows-x64下载安装可用
- vgg模型-图像分类算法对水果识别-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- vgg模型-python语言pytorch框架训练识别化妆品分类-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- shufflenet模型-基于人工智能的卷积网络训练识别狗的表情-不含数据集图片-含逐行注释和说明文档.zip
- shufflenet模型-python语言pytorch框架训练识别张嘴闭嘴-不含数据集图片-含逐行注释和说明文档.zip
- resnet模型-基于人工智能的卷积网络训练识别面部表情识别-不含数据集图片-含逐行注释和说明文档
- resnet模型-python语言pytorch框架训练识别香蕉品质-不含数据集图片-含逐行注释和说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功