MCPcopy Create free account
hub / github.com/PRQL/prql / read_input

Method read_input

prqlc/prqlc/src/cli/mod.rs:495–533  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

493 }
494
495 fn read_input(&mut self) -> Result<(SourceTree, String)> {
496 // Possibly this should be called by the relevant subcommands passing in
497 // `input`, rather than matching on them and grabbing `input` from
498 // `self`? But possibly if everything moves to `io_args`, then this is
499 // quite reasonable?
500 use Command::*;
501 let io_args = match self {
502 Parse { io_args, .. }
503 | Lex { io_args, .. }
504 | Collect(io_args)
505 | Compile { io_args, .. }
506 | Debug(DebugCommand::Annotate(io_args) | DebugCommand::Lineage { io_args, .. }) => {
507 io_args
508 }
509 Experimental(ExperimentalCommand::GenerateDocs { io_args, .. }) => io_args,
510 Experimental(ExperimentalCommand::Highlight(io_args)) => io_args,
511 _ => unreachable!(),
512 };
513 let input = &mut io_args.input;
514
515 // Don't wait without a prompt when running `prqlc compile` —
516 // it's confusing whether it's waiting for input or not. This
517 // offers the prompt.
518 //
519 // See https://github.com/PRQL/prql/issues/3228 for details on us not
520 // yet using `input.is_tty()`.
521 if input.path() == Path::new("-") && std::io::stdin().is_terminal() {
522 #[cfg(unix)]
523 eprintln!("Enter PRQL, then press ctrl-d to compile:\n");
524 #[cfg(windows)]
525 eprintln!("Enter PRQL, then press ctrl-z to compile:\n");
526 }
527
528 let sources = read_files(input)?;
529
530 let main_path = io_args.main_path.clone().unwrap_or_default();
531
532 Ok((sources, main_path))
533 }
534
535 fn write_output(&mut self, data: &[u8]) -> std::io::Result<()> {
536 use Command::{Collect, Compile, Debug, Experimental, Lex, Parse};

Callers 1

run_io_commandMethod · 0.80

Calls 1

read_filesFunction · 0.85

Tested by

no test coverage detected