-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain.rs
More file actions
42 lines (37 loc) · 1.49 KB
/
main.rs
File metadata and controls
42 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::{env, process::ExitCode, sync::Arc};
use vite_path::{AbsolutePath, current_dir};
use vite_task::{
CLIArgs, Session,
session::reporter::{ExitStatus, LabeledReporter},
};
use vite_task_bin::{CustomTaskSubcommand, NonTaskSubcommand, OwnedSessionCallbacks};
#[tokio::main]
async fn main() -> anyhow::Result<ExitCode> {
let exit_status = run().await?;
Ok(exit_status.0.into())
}
async fn run() -> anyhow::Result<ExitStatus> {
let cwd: Arc<AbsolutePath> = current_dir()?.into();
// Parse the CLI arguments and see if they are for vite-task or not
let args = match CLIArgs::<CustomTaskSubcommand, NonTaskSubcommand>::try_parse_from(env::args())
{
Ok(ok) => ok,
Err(err) => {
err.exit();
}
};
let task_cli_args = match args {
CLIArgs::Task(task_cli_args) => task_cli_args,
CLIArgs::NonTask(NonTaskSubcommand::Version) => {
// Non-task subcommands are not handled by vite-task's session.
println!("{}", env!("CARGO_PKG_VERSION"));
return Ok(ExitStatus::SUCCESS);
}
};
let mut owned_callbacks = OwnedSessionCallbacks::default();
let mut session = Session::init(owned_callbacks.as_callbacks())?;
let plan = session.plan_from_cli(cwd, task_cli_args).await?;
// Create reporter and execute
let reporter = LabeledReporter::new(std::io::stdout(), session.workspace_path());
Ok(session.execute(plan, Box::new(reporter)).await.err().unwrap_or(ExitStatus::SUCCESS))
}