Bargs
🛥️ The ultimate Command Line Interface builder for Crystal
Install / Use
/learn @crystalrealm/BargsREADME
Bargs
The ultimate Command Line Interface builder for
Crystal
Bargs aims to be the successor to Commander, while remaining tiny, unopinionated, and simple to use.
Installation
Add this to your application's shard.yml:
dependencies:
bargs:
github: crystalrealm/bargs
Usage
require "bargs"
# Creating a new Bargs interface
# By default, Bargs uses the global ARGV variable, but you can also specify an array of strings, and it will use that.
interface = Bargs::CLI.new
# This message gets shown if no flags or commands are given.
interface.help = "Help message goes here."
# Add an 'install' command
interface.command "install"
# Define a save flag. Also making sure it accepts an argument.
interface.flag "save" do |flag|
flag.short = "s"
# NOTE: This here is totally optional.
flag.accepts_arg = true
end
args = interface.process
Here, args contains a Bargs::ProcessedInput.
A processed input contains the following fields & methods:
.command_name
Returns the parsed command, if any.
.has?(flag_name : String) : Bool
Returns true if the given flag name was matched in the input.
.get(flag_name : String) : Bargs::Flag
Returns the flag matched with the given name.
Also note: A flag will always be stored with their long names in focus, so you need to provide the actual long flag name to get & has?.
Contributing
- Fork it (https://github.com/crystalrealm/bargs/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- molnarmark Mark Molnar - creator, maintainer
Related Skills
node-connect
352.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
