@@ -50,31 +50,34 @@ local formats = {
50
50
}
51
51
52
52
M .generator_factory = function (opts )
53
+ local command , args , on_output , format , to_stderr , to_stdin , ignore_errors ,
54
+ check_exit_code = opts .command , opts .args , opts .on_output ,
55
+ opts .format , opts .to_stderr , opts .to_stdin ,
56
+ opts .ignore_errors , opts .check_exit_code
57
+
58
+ local _validated
59
+ local validate_opts = function ()
60
+ validate ({
61
+ command = {command , " string" },
62
+ args = {args , " table" , true },
63
+ on_output = {on_output , " function" },
64
+ format = {
65
+ format , function (a )
66
+ return not a or vim .tbl_contains (vim .tbl_values (formats ), a )
67
+ end , " raw, line, or json"
68
+ },
69
+ to_stderr = {to_stderr , " boolean" , true },
70
+ to_stdin = {to_stdin , " boolean" , true },
71
+ ignore_errors = {ignore_errors , " boolean" , true },
72
+ check_exit_code = {check_exit_code , " function" , true }
73
+ })
74
+
75
+ _validated = true
76
+ end
77
+
53
78
return {
54
79
fn = function (params , done )
55
- local command , args , on_output , format , to_stderr , to_stdin ,
56
- ignore_errors , check_exit_code = opts .command , opts .args ,
57
- opts .on_output , opts .format ,
58
- opts .to_stderr ,
59
- opts .to_stdin ,
60
- opts .ignore_errors ,
61
- opts .check_exit_code
62
-
63
- validate ({
64
- command = {command , " string" },
65
- args = {args , " table" , true },
66
- on_output = {on_output , " function" },
67
- format = {
68
- format , function (a )
69
- return not a or
70
- vim .tbl_contains (vim .tbl_values (formats ), a )
71
- end , " raw, line, or json"
72
- },
73
- to_stderr = {to_stderr , " boolean" , true },
74
- to_stdin = {to_stdin , " boolean" , true },
75
- ignore_errors = {ignore_errors , " boolean" , true },
76
- check_exit_code = {check_exit_code , " function" , true }
77
- })
80
+ if not _validated then validate_opts () end
78
81
79
82
local wrapper = function (error_output , output )
80
83
if to_stderr then
0 commit comments