Skip to content

Commit 353b102

Browse files
committed
update examples/validation/README.md
1 parent 52a3308 commit 353b102

File tree

1 file changed

+23
-49
lines changed

1 file changed

+23
-49
lines changed

examples/validations/README.md

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,103 +22,77 @@ failure, or an empty string on success.
2222
## `bashly.yml`
2323

2424
```yaml
25-
name: calc
25+
name: validate
2626
help: Sample application demonstrating validations
2727
version: 0.1.0
2828

2929
commands:
30-
- name: add
31-
short: a
30+
- name: calc
3231
help: Add two numbers
3332

3433
args:
3534
- name: first
3635
help: First number
3736
required: true
3837

39-
# Specify one or more validation types (as string or array)
40-
# This validation will look for a function named `validate_integer` in your
41-
# script.
38+
# Specify a validation function.
39+
# Bashly will look for a function named `validate_integer` in your
40+
# script, you can use any name as long as it has a matching function.
4241
validate: integer
4342
- name: second
4443
help: Second number
45-
46-
# Using the array syntax, you can specify more than one validations
47-
validate:
48-
- integer
44+
validate: integer
4945

5046
flags:
51-
- long: --multiply
52-
short: -m
53-
arg: factor
54-
help: Multiply the result
47+
- long: --save
48+
arg: path
49+
help: Save the result to a file
5550

5651
# Validations also work on flags (when they have arguments)
57-
validate: integer
52+
validate: file_exists
5853
```
5954
6055
6156
6257
## Generated script output
6358
64-
### `$ ./calc -h`
65-
66-
```shell
67-
calc - Sample application demonstrating validations
68-
69-
Usage:
70-
calc [command]
71-
calc [command] --help | -h
72-
calc --version | -v
73-
74-
Commands:
75-
add Add two numbers
76-
77-
Options:
78-
--help, -h
79-
Show this help
80-
81-
--version, -v
82-
Show version number
83-
84-
85-
86-
```
87-
88-
### `$ ./calc add 1 2 --multiply 3`
59+
### `$ ./validate calc 1 2 --save README.md`
8960

9061
```shell
91-
# this file is located in 'src/add_command.sh'
92-
# code for 'calc add' goes here
62+
# this file is located in 'src/calc_command.sh'
63+
# code for 'validate calc' goes here
9364
# you can edit it freely and regenerate (it will not be overwritten)
9465
args:
9566
- ${args[first]} = 1
96-
- ${args[--multiply]} = 3
67+
- ${args[--save]} = README.md
9768
- ${args[second]} = 2
9869
9970
10071
```
10172

102-
### `$ ./calc add A`
73+
### `$ ./validate calc A`
10374

10475
```shell
105-
validation error: FIRST must be an integer
76+
validation error in FIRST:
77+
must be an integer
10678
10779
10880
```
10981

110-
### `$ ./calc add 1 B`
82+
### `$ ./validate calc 1 B`
11183

11284
```shell
113-
validation error: SECOND must be an integer
85+
validation error in SECOND:
86+
must be an integer
11487
11588
11689
```
11790

118-
### `$ ./calc add 1 2 --multiply C`
91+
### `$ ./validate calc 1 2 --save no-such-file.txt`
11992

12093
```shell
121-
validation error: --multiply, -m FACTOR must be an integer
94+
validation error in --save PATH:
95+
must be an existing file
12296
12397
12498
```

0 commit comments

Comments
 (0)