cli: add json data type
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
6048ad905a
commit
14d5a51822
1 changed files with 12 additions and 0 deletions
|
@ -58,6 +58,18 @@ const types = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
json: {
|
||||||
|
parse: function(ctx, name, val) {
|
||||||
|
try {
|
||||||
|
val = json(val);
|
||||||
|
} catch (e) {
|
||||||
|
return ctx.invalid_argument('Invalid JSON data');
|
||||||
|
}
|
||||||
|
if (this.data_type != null && type(val) != this.data_type)
|
||||||
|
ctx.invalid_argument(`Invalid data type: %s, expected: %s`, type(val), this.data_type);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
},
|
||||||
enum: {
|
enum: {
|
||||||
parse: function(ctx, name, val) {
|
parse: function(ctx, name, val) {
|
||||||
if (this.no_validate)
|
if (this.no_validate)
|
||||||
|
|
Loading…
Reference in a new issue