Skip to content

Commit 23d7a6a

Browse files
author
devnote-dev
committed
feat: v2.0.0!
1 parent 111a1de commit 23d7a6a

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
# CLI.cr
2-
Yet another Crystal command line interface library.
2+
3+
Yet another command line interface library for Crystal. Based on [spf13/cobra](https://github.com/spf13/cobra), CLI.cr is built to be almost entirely modular, giving you absolute control over almost everything - there isn't even a default help command or flag!
34

45
## Installation
6+
57
1. Add the dependency to your `shard.yml`:
68
```yaml
79
dependencies:
810
cli:
911
github: devnote-dev/cli.cr
12+
branch: stable
1013
```
1114
1215
2. Run `shards install`
1316

1417
## Usage
18+
1519
```crystal
1620
require "cli"
1721
1822
class MainCmd < CLI::Command
19-
def setup
23+
def setup : Nil
2024
@name = "greet"
21-
@description = "Greets a person"
25+
description = "Greets a person"
2226
add_argument "name", desc: "the name of person to greet", required: true
23-
add_option "caps", short: "c", desc: "greet with capitals"
27+
add_option 'c', "caps", desc: "greet with capitals"
28+
add_option 'h', "help", desc: "sends help information"
29+
end
30+
31+
def pre_run(args, options)
32+
if options.has? "help"
33+
puts help_template # generated using CLI::Formatter
34+
35+
false
36+
else
37+
true
38+
end
2439
end
2540
26-
def execute(args, options) : Nil
41+
def run(args, options) : Nil
2742
msg = "Hello, #{args.get("name")}!"
2843
2944
if options.has? "caps"
@@ -34,23 +49,21 @@ class MainCmd < CLI::Command
3449
end
3550
end
3651
37-
app = CLI::Application.new
38-
app.add_command MainCmd, default: true
52+
main = MainCmd.new
53+
main.execute ARGV
54+
```
3955

40-
app.run ARGV
4156
```
42-
```shell
4357
$ crystal greet.cr -h
44-
Greets a person
45-
4658
Usage:
4759
greet <arguments> [options]
4860

4961
Arguments:
50-
person the person to greet
62+
name the name of person to greet (required)
5163

5264
Options:
5365
-c, --caps greet with capitals
66+
-h, --help sends help information
5467

5568
$ crystal greet.cr Dev
5669
Hello, Dev!

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: cli
22
description: expandable command line interface library
3-
version: 1.0.0
3+
version: 2.0.0
44
crystal: 1.5.0
55

66
repository: https://github.com/devnote-dev/cli.cr

src/cli.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "./cli/*"
22

33
module CLI
4-
VERSION = "0.1.0"
4+
VERSION = "2.0.0"
55
end

0 commit comments

Comments
 (0)