@@ -22,103 +22,77 @@ failure, or an empty string on success.
22
22
## ` bashly.yml `
23
23
24
24
``` yaml
25
- name : calc
25
+ name : validate
26
26
help : Sample application demonstrating validations
27
27
version : 0.1.0
28
28
29
29
commands :
30
- - name : add
31
- short : a
30
+ - name : calc
32
31
help : Add two numbers
33
32
34
33
args :
35
34
- name : first
36
35
help : First number
37
36
required : true
38
37
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 .
42
41
validate : integer
43
42
- name : second
44
43
help : Second number
45
-
46
- # Using the array syntax, you can specify more than one validations
47
- validate :
48
- - integer
44
+ validate : integer
49
45
50
46
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
55
50
56
51
# Validations also work on flags (when they have arguments)
57
- validate : integer
52
+ validate : file_exists
58
53
` ` `
59
54
60
55
61
56
62
57
## Generated script output
63
58
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`
89
60
90
61
` ` ` 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
93
64
# you can edit it freely and regenerate (it will not be overwritten)
94
65
args:
95
66
- ${args[first]} = 1
96
- - ${args[--multiply ]} = 3
67
+ - ${args[--save ]} = README.md
97
68
- ${args[second]} = 2
98
69
99
70
100
71
` ` `
101
72
102
- # ## `$ ./calc add A`
73
+ # ## `$ ./validate calc A`
103
74
104
75
` ` ` shell
105
- validation error: FIRST must be an integer
76
+ validation error in FIRST:
77
+ must be an integer
106
78
107
79
108
80
` ` `
109
81
110
- # ## `$ ./calc add 1 B`
82
+ # ## `$ ./validate calc 1 B`
111
83
112
84
` ` ` shell
113
- validation error: SECOND must be an integer
85
+ validation error in SECOND:
86
+ must be an integer
114
87
115
88
116
89
` ` `
117
90
118
- # ## `$ ./calc add 1 2 --multiply C `
91
+ # ## `$ ./validate calc 1 2 --save no-such-file.txt `
119
92
120
93
` ` ` shell
121
- validation error: --multiply, -m FACTOR must be an integer
94
+ validation error in --save PATH:
95
+ must be an existing file
122
96
123
97
124
98
` ` `
0 commit comments