Parse one command block (directive line plus indentation-structured body).
(input: &str)
| 425 | |
| 426 | /// Parse one command block (directive line plus indentation-structured body). |
| 427 | fn parse_command(input: &str) -> anyhow::Result<Command> { |
| 428 | let lines = lex(input); |
| 429 | let (header, body) = lines.split_first().context("empty command")?; |
| 430 | ensure!(header.indent == 0, "directive must not be indented"); |
| 431 | let (verb, args, flags) = parse_header(&header.text)?; |
| 432 | let command = match verb.as_str() { |
| 433 | "define-schema" => Command::DefineSchema { |
| 434 | name: req(&args, "name")?.to_string(), |
| 435 | columns: columns_from_body(body)?, |
| 436 | }, |
| 437 | "write-single-ts" => Command::WriteSingleTs { |
| 438 | shard: req(&args, "shard")?.to_string(), |
| 439 | schema: opt_string(&args, "schema"), |
| 440 | ts: req_u64(&args, "ts")?, |
| 441 | count: req_u64(&args, "count")?, |
| 442 | start: opt_u64(&args, "start")?.unwrap_or(0), |
| 443 | row_bytes: opt_usize(&args, "row-bytes")?, |
| 444 | }, |
| 445 | "write-spread" => Command::WriteSpread { |
| 446 | shard: req(&args, "shard")?.to_string(), |
| 447 | schema: opt_string(&args, "schema"), |
| 448 | count: req_u64(&args, "count")?, |
| 449 | n_ts: req_u64(&args, "n-ts")?, |
| 450 | start: opt_u64(&args, "start")?.unwrap_or(0), |
| 451 | row_bytes: opt_usize(&args, "row-bytes")?, |
| 452 | }, |
| 453 | "write-rows" => Command::WriteRows { |
| 454 | shard: req(&args, "shard")?.to_string(), |
| 455 | schema: opt_string(&args, "schema"), |
| 456 | ts: req_u64(&args, "ts")?, |
| 457 | rows: rows_from_body(body)?, |
| 458 | }, |
| 459 | "define-index" => Command::DefineIndex { |
| 460 | source_id: req_u64(&args, "source")?, |
| 461 | index_id: req_u64(&args, "index")?, |
| 462 | shard: req(&args, "shard")?.to_string(), |
| 463 | schema: opt_string(&args, "schema"), |
| 464 | key: parse_usize_list(req(&args, "key")?)?, |
| 465 | as_of: req_u64(&args, "as-of")?, |
| 466 | upper: req_u64(&args, "upper")?, |
| 467 | }, |
| 468 | "schedule" => Command::Schedule { |
| 469 | id: req_u64(&args, "id")?, |
| 470 | }, |
| 471 | "allow-compaction" => Command::AllowCompaction { |
| 472 | id: req_u64(&args, "id")?, |
| 473 | frontier: req_u64(&args, "frontier")?, |
| 474 | }, |
| 475 | "allow-writes" => Command::AllowWrites { |
| 476 | id: req_u64(&args, "id")?, |
| 477 | }, |
| 478 | "await-frontier" => Command::AwaitFrontier { |
| 479 | id: req_u64(&args, "id")?, |
| 480 | ts: req_u64(&args, "ts")?, |
| 481 | timeout_secs: opt_u64(&args, "timeout-secs")?, |
| 482 | allow_timeout: flags.iter().any(|f| f == "allow-timeout"), |
| 483 | }, |
| 484 | "count" => Command::Count { |
no test coverage detected