-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.cr
60 lines (51 loc) · 1.3 KB
/
demo.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require "../src/cliq"
class GreetWorld < Cliq::Command
command "greet world"
summary "Greet the world" # Shown on top-level help-screen
description "World greeter" # Shown on command help-screen
flags({
count: Int32,
})
# `#call` gets called when your command is invoked.
#
# It's the only mandatory method that your Cliq::Command
# subclass must have. Here you can see how to access the
# flag values (`@count`) and positional args (`args`).
def call(args)
@count.times do
puts "Hello world!"
end
end
end
class GreetPerson < Cliq::Command
command "greet person"
summary "Greet someone"
args ["<name> Name to greet"]
# See https://github.com/Papierkorb/toka#advanced-usage
flags({
yell: Bool?,
count: {
type: Int32,
default: 1,
value_name: "TIMES",
description: "Print the greeting this many times (default: 1)",
},
})
def call(args)
raise Cliq::Error.new("Missing argument: <name>") if args.size < 1
greeting = "Hello #{args[0]}!"
greeting = greeting.upcase if @yell
@count.times do
puts greeting
end
end
end
class Ping < Cliq::Command
command "ping"
summary "Minimum viable example"
def call(args)
puts "pong"
end
end
# Let's go!
Cliq.invoke(ARGV) unless ENV["ENV"]? == "test"