party_run/cli_commands/
batch.rs1use std::path::Path;
4
5use crate::{
6 cli::BatchArgs,
7 parser::command_parser::CommandParser,
8 party_command::{self, make_default_commands},
9 schdeuler,
10 util::{check_file_path, make_counter_blue, make_message_bright_green, DEFAULT_PARTY_CONF},
11};
12
13pub fn batch(batch_args: BatchArgs) -> anyhow::Result<()> {
15 if let Some(file_path) = &batch_args.file {
17 check_file_path(file_path)?;
18 }
19
20 let file_path = batch_args.file.unwrap_or(DEFAULT_PARTY_CONF.to_string());
21 let commands = if Path::new(&file_path).exists() {
22 let parser = CommandParser {
23 path: file_path.to_string(),
24 };
25 let tasks = parser.parse()?;
26 party_command::convert_toml_tasks(tasks.tasks)
27 } else {
28 make_default_commands()
29 };
30
31 let no_commands = commands.len();
32 let batches = schdeuler::schedule_commands(commands);
33
34 println!(
35 "{} tasks will be run in {} batches. All tasks in a batch are run in parallel.",
36 no_commands,
37 batches.len()
38 );
39
40 for (i, batch) in batches.iter().enumerate() {
41 println!(
42 "Batch {} with {}:",
43 make_counter_blue(i + 1, batches.len()),
44 make_message_bright_green(&format!("{} commands", batch.len()))
45 );
46 for task in batch {
47 println!(" - {}", task);
48 }
49 }
50
51 Ok(())
52}