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

Method run

prqlc/prqlc/src/cli/mod.rs:292–349  ·  view source on GitHub ↗

Entrypoint called by [`main`]

(&mut self)

Source from the content-addressed store, hash-verified

290impl Command {
291 /// Entrypoint called by [`main`]
292 pub fn run(&mut self) -> Result<()> {
293 match self {
294 Command::Watch(command) => watch::run(command),
295 Command::ListTargets => self.list_targets(),
296 // Format is handled differently to the other IO commands, since it
297 // always writes to the same output.
298 Command::Format { input } => {
299 let sources = read_files(input)?;
300 let root = sources.root;
301
302 for (path, source) in sources.sources {
303 let ast = prql_to_pl(&source)?;
304
305 // If we're writing to stdout (though could this be nicer?
306 // We're discarding many of the benefits of Clio here...)
307 if path.as_os_str() == "" {
308 let mut output: Output = Output::new(input.path())?;
309 output.write_all(&pl_to_prql(&ast)?.into_bytes())?;
310 break;
311 }
312
313 let path_buf = root
314 .as_ref()
315 .map_or_else(|| path.clone(), |root| root.join(&path));
316 let path_str = path_buf.to_str().ok_or_else(|| {
317 anyhow!("Path `{}` is not valid UTF-8", path_buf.display())
318 })?;
319 let mut output: Output = Output::new(path_str)?;
320
321 output.write_all(&pl_to_prql(&ast)?.into_bytes())?;
322 }
323 Ok(())
324 }
325 Command::ShellCompletion { shell } => {
326 shell.generate(&mut Cli::command(), &mut std::io::stdout());
327 Ok(())
328 }
329 Command::Debug(DebugCommand::Ast) => {
330 prqlc::ir::pl::print_mem_sizes();
331 Ok(())
332 }
333 Command::Debug(DebugCommand::JsonSchema { ir_type }) => {
334 let schema = match ir_type {
335 IntermediateRepr::Pl => schema_for!(pl::ModuleDef),
336 IntermediateRepr::Rq => schema_for!(rq::RelationalQuery),
337 IntermediateRepr::Lineage => schema_for!(FrameCollector),
338 };
339 io::stdout().write_all(&serde_json::to_string_pretty(&schema)?.into_bytes())?;
340 Ok(())
341 }
342 #[cfg(feature = "lsp")]
343 Command::Lsp => match lsp::run() {
344 Ok(_) => Ok(()),
345 Err(err) => Err(anyhow!(err)),
346 },
347 _ => self.run_io_command(),
348 }
349 }

Callers 3

testsFunction · 0.45
typingFunction · 0.45
mainFunction · 0.45

Calls 7

read_filesFunction · 0.85
print_mem_sizesFunction · 0.85
list_targetsMethod · 0.80
run_io_commandMethod · 0.80
runFunction · 0.70
prql_to_plFunction · 0.50
pl_to_prqlFunction · 0.50

Tested by

no test coverage detected