OCaml: Add simulate (dry run) configuration option
This commit is contained in:
parent
1f16024c9e
commit
9e9a9566db
5 changed files with 42 additions and 25 deletions
|
|
@ -21,6 +21,8 @@ let lex_keyword (literal: string): token =
|
|||
match literal with
|
||||
| "su_command" -> Key SuCommand
|
||||
| "su_command_quoted" -> Key SuCommandQuoted
|
||||
| "interactive" -> Key Interactive
|
||||
| "simulate" -> Key Simulate
|
||||
| _ -> Key Unknown
|
||||
|
||||
let lex_keyvalue (literal: string): token = Value literal
|
||||
|
|
@ -31,6 +33,7 @@ let string_of_token (token: token): string =
|
|||
| SuCommand -> "[ KEY: su_command ]"
|
||||
| SuCommandQuoted -> "[ KEY: su_command_quoted ]"
|
||||
| Interactive -> " [ KEY: interactive ]"
|
||||
| Simulate -> " [ KEY: simulate ]"
|
||||
| Unknown -> "[ UNKNOWN KEY ]")
|
||||
| Equal -> "[ OP: equal ]"
|
||||
| Value v -> "[ VAL: " ^ v ^ " ]"
|
||||
|
|
|
|||
|
|
@ -30,20 +30,14 @@ let check (config: Schema.main): Schema.main =
|
|||
{ config with su_command_quoted = false }
|
||||
| Default, _ -> config
|
||||
|
||||
let update config key (value: string): Schema.main =
|
||||
let update (config: Schema.main) (key: Lexer.key) (value: string): Schema.main =
|
||||
elog ~context:Parsing $ "[c.parser.update] Matching value '" ^ value ^ "'";
|
||||
match key with
|
||||
| Schema.SuCommand ->
|
||||
{ config with Schema.su_command = String.split_on_char ' ' value }
|
||||
| SuCommandQuoted ->
|
||||
{ config with
|
||||
Schema.su_command_quoted = parse_boolean key value }
|
||||
| Interactive ->
|
||||
{ config with
|
||||
Schema.interactive = bool_of_string value }
|
||||
| Unknown ->
|
||||
elog ~context:Parsing $ "[c.parser.update] Dropped value: unknown key";
|
||||
config
|
||||
| SuCommand -> { config with su_command = String.split_on_char ' ' value }
|
||||
| SuCommandQuoted -> { config with su_command_quoted = parse_boolean key value }
|
||||
| Interactive -> { config with interactive = bool_of_string value }
|
||||
| Simulate -> { config with simulate = bool_of_string value }
|
||||
| Unknown -> elog ~context:Parsing $ "[c.parser.update] Dropped value: unknown key"; config
|
||||
|
||||
let parse tokens: Schema.main =
|
||||
let rec parse_tokens tokens config ready_key =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue