-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathpizza.ts
executable file
·59 lines (52 loc) · 1.88 KB
/
pizza.ts
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
#!/usr/bin/env ts-node
import { program } from "@caporal/core"
program
.version("1.0.0")
.description("Order pizza right from your terminal!")
// the "order" command
.command("order", "Order a pizza")
.alias("give-it-to-me")
// <kind> will be auto-magicaly autocompleted by providing the user with 3 choices
.argument(
"<kind>",
"Kind of pizza you want to order from the shop. You may want to add new types of pizza by asking the chef, but the validator won't pass!",
{ default: ["margherita", "hawaiian", "fredo"] },
)
.argument("<from-store>", "Which store to order from", {
validator: ["New-York", "Portland", "Paris"],
})
.argument("<account>", "Which account id to use", {
validator: program.NUMBER,
default: 1875896,
})
.argument("[other-request...]", "Other requests")
.option("-n, --number <num>", "Number of pizza", {
validator: program.NUMBER,
required: true,
})
.option("-d, --discount <code>", "Discount code", {
validator: /^[a-z]{3}[0-9]{5,}$/i,
})
.option("-p, --pay-by <mean>", "Pay by option", {
validator: ["cash", "card"],
required: true,
})
// enable auto-completion for -p | --pay-by argument using a Promise
// --extra will be auto-magicaly autocompleted by providing the user with 3 choices
.option("-e <ingredients>", "Add extra ingredients", {
validator: ["pepperoni", "onion", "cheese"],
})
.option("--add-ingredients <ingredients...>", "Add extra ingredients", {
validator: program.ARRAY,
})
.action(function ({ args, options, logger }) {
logger.info("Command 'order' called with:")
logger.info("arguments: %j", args)
logger.info("options: %j", options)
})
.command("cancel", "Cancel an order")
.argument("<order-id>", "Order id", { validator: program.NUMBER })
.action(({ args, logger }) => {
logger.info("Order id #%s canceled", args.orderId)
})
program.run()