试用
Argc是一个Bash CLI框架,也是一个基于Bash的命令运行器。
Argc强大之处在于它简化了构建全功能CLI的过程。通过注释定义CLI,你可以专注于核心逻辑,而不必处理参数解析、使用文本、错误消息和其他样板代码。 如果你对Python Click有了解的话,那么Argc就是Bash版本的Click。
Argc核心特性:
- Effortless Argument Parsing
- Standalone Bash Script Creation
- Cross-shell Autocompletion
- Man Page Generation
- Environment Variable Integration
- Task Automation
- Cross-Platform Compatibility
此外Argc还是一个强大的脚本运行期,借助Argcfile.sh可以构建类似于Makefile的命令集合,非常适合喜欢Bash脚本的人使用。
个人认为Argc是一个非常有潜力的工具,功能丰富,Bash支持,其提供的注释指令,对AI非常友好,代码提示非常方便,可以大大提高开发效率。
注意:argc可以运行各种命令和参数,所以传统的--help来显示命令行帮助,要调整为argc --argc-help。
Argc有一个symbol特性,这个很少被用到,这里说明一下。首先是声明symbol变量,如下:
# @meta symbol +toolchain[`_choice_toolchain`]
然后在脚本中使用,这个和参数没有什么区别,如下
echo ${argc_toolchain}
接下来就是命令行使用symbol,如cli_app +stable task_name param这样即可。
Argc & Friends
- Amber: a programming language compiled to bash - https://amber-lang.com/
- ShellCheck: https://ithub.com/koalaman/shellcheck
- shfmt: https://github.com/mvdan/sh
- Explainshell: https://explainshell.com/
- Bats: https://github.com/bats-core/bats-core
- JetBrains Argc Shell Assistant: https://plugins.jetbrains.com/plugin/25143-argc-shell-assistant
References
- Argc: https://github.com/sigoden/argc
- GNU Bash: https://www.gnu.org/software/bash/
- Bash Cheat Sheet: https://cheatsheets.zip/bash
- Bash Scripting School: https://www.youtube.com/@linuxadminhacks
- Bash Interactive Sheet: https://speedsheet.io/s/bash
- Introduction to Bash Scripting: https://github.com/bobbyiliev/introduction-to-bash-scripting
- Google Shell Style Guide: https://google.github.io/styleguide/shellguide.html
- Bash-Oneliner: https://github.com/onceupon/Bash-Oneliner
- commandlinefu: https://www.commandlinefu.com/