clicr
Version, currently 0.4.224 versions
- 1.1.1latestOct 28, 2020
- 1.1.0not indexedOct 28, 2020
- 1.0.0not indexedOct 28, 2020
- 0.7.0not indexedOct 28, 2020
- 0.6.0not indexedOct 28, 2020
- 0.5.1not indexedOct 28, 2020
- 0.5.0not indexedOct 28, 2020
- 0.4.2not indexedOct 28, 2020
- 0.4.1not indexedOct 28, 2020
- 0.4.0not indexedOct 28, 2020
- 0.3.9not indexedOct 28, 2020
- 0.3.8not indexedOct 28, 2020
- 0.3.7not indexedOct 28, 2020
- 0.3.6not indexedOct 28, 2020
- 0.3.5not indexedOct 28, 2020
- 0.3.4not indexedOct 28, 2020
- 0.3.3not indexedOct 28, 2020
- 0.3.2not indexedOct 28, 2020
- 0.3.1not indexedOct 28, 2020
- 0.3.0not indexedOct 28, 2020
- 0.2.1not indexedOct 28, 2020
- 0.2.0not indexedOct 28, 2020
- 0.1.1not indexedOct 28, 2020
- 0.1.0not indexedOct 28, 2020
github.com/j8r/clicr
A simple declarative command line interface builder
32 stars
2 dependents
License: ISC
Nothing has been indexed for 0.4.2 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
clicr:
github: j8r/clicr
version: ~> 0.4.2Then run:
shards installshard.yml
No shard.yml has been indexed for 0.4.2. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
# Clicr
[](https://cloud.drone.io/j8r/clicr)
[](https://en.wikipedia.org/wiki/ISC_license)
Command Line Interface for Crystal
A simple Command line interface builder which aims to be easy to use.
## Installation
Add the dependency to your `shard.yml`:
```yaml
dependencies:
clicr:
github: j8r/clicr
```
## Features
This library uses generics, thanks to Crystal's powerful type-inference, and few macros, to provide this following advantages:
- Compile time validation - methods must accept all possible options and arguments
- No possible double commands/options at compile-time
- Declarative `NamedTuple` configuration
- Customizable configuration - supports all languages (See [Clicr.new](src/clicr.cr) parameters)
- Fast execution, limited runtime
## Usage
### Simple example
```crystal
require "clicr"
Clicr.new(
label: "This is my app.",
commands: {
talk: {
label: "Talk",
action: {"CLI.say": "t"},
arguments: %w(directory),
options: {
name: {
label: "Your name",
default: "foo",
},
no_confirm: {
short: 'y',
label: "Print the name",
},
},
},
},
).run
module CLI
def self.say(arguments, name, no_confirm)
puts arguments, name, no_confirm
end
end
```
Example of commands:
```
$ myapp --help
Usage: myapp COMMANDS [OPTIONS]
Myapp can do everything
COMMANDS
t, talk Talk
OPTIONS
--name=foo Your name
-y, --no-confirm Print the name
'myapp --help' to show the help.
```
```
$ myapp talk /tmp name=bar
no, bar in /tmp
```
```
$ myapp talk home name=bar -y
yes, bar in home
```
```
$ myapp talk test
no, foo in test
```
### Advanced example
See the one in the [spec test](spec/clicr_spec.cr)
### CLI Composition
It's also possible to merge several commands or options together.
```crystal
other = {
pp: {
label: "It pp",
action: "pp"
}
}
Clicr.new(
label: "Test app",
commands: {
puts: {
alias: 'p',
label: "It puts",
action: "puts",
}.merge(other)
}
)
```
Help output:
```
Usage: myapp COMMAND
Test app
COMMAND
p, puts It puts
pp It pp
'myapp --help' to show the help.
```
## Reference
### Commands
Example: `s`, `start`
```crystal
commands: {
short: {
action: { "say": "s" },
label: "Starts the server",
description: <<-E.to_s,
This is a full multi-line description
explaining the command
E,
}
}
```
* `action` is a `NamedTuple` with as key the method to call, and as a value a command alia, which can be empty for none.
* in `action`, parentheses can be added to determine the arguments placement, like `File.new().file`
* `label` is supposed to be short, one-line description
* `description` can be a multi-line description of the command. If not set, `label` will be used.
### Arguments
Example: `command FooBar`, `command mysource mytarget`
```crystal
arguments: %w(directory names)
```
```crystal
arguments: {"source", "target"}
```
* if a `Tuple` is given, the arguments number **must** be exactly the `Tuple` size.
* if an `Array` is given, the arguments number must be at least, or more, the `Array` size
### Options
#### Boolean options
Example: `-y`, `--no-confirm`
```crystal
options: {
no_confirm: {
short: 'y',
label: "No confirmations",
}
}
```
* `short` creates a short alias of one character - must be a `Char`
* concatenating single characters arguments like `-Ry1` is possible
* dashes `-`, being invalid named arguments, will be replaced by `_` when calling the action method.
Special case: the `help_option`, which is set to `"help"` with the options `-h, --help` by default,
shows the help of the current (sub)command
#### String options
Example: `--name=foo`, or `--name foo`
```crystal
options: {
name: {
label: "This is your name",
default: "Foobar",
}
}
```
* an optional `default` value can be set.
* if a `default` is not set, a `type` can be defined to cast from a given type, instead of a raw `String`. For example, `type: Int32` will call `Int32.new`.
* can only be `String` (because arguments passed as `ARGV` are `Array(String)`) - if others type are needed, the cast must be done after the `action` method call
## License
Copyright (c) 2020 Julien Reichardt - ISC License
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.4.2- Tagged
- Oct 28, 2020
- Commit
5e402b9af5e8- Indexed
- not yet
Dependents
Repository
github.com/j8r/clicr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 24