Added support for tasks without commands
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/pr Build is failing Details

Added description output for tasks
This commit is contained in:
Joe Bellus 2022-09-25 15:07:46 -04:00
parent 43af1fd35d
commit 7a4ff1a345
4 changed files with 29 additions and 10 deletions

2
Cargo.lock generated
View File

@ -193,7 +193,7 @@ dependencies = [
[[package]]
name = "conductor"
version = "2.0.0"
version = "2.0.1"
dependencies = [
"actix",
"actix-rt",

View File

@ -1,6 +1,6 @@
[package]
name = "conductor"
version = "2.0.0"
version = "2.0.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -28,6 +28,15 @@ impl From<&str> for Command {
}
}
impl Command {
pub fn is_empty(&self) -> bool {
match self {
Command::Multiple(v) => v.is_empty(),
Command::Single(v) => v.is_empty(),
}
}
}
impl std::fmt::Display for Command {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
@ -98,7 +107,7 @@ impl Project {
.flat_map(|jobs| jobs.to_vec())
.collect::<Vec<_>>();
jobs.push(job);
Jobs::new(jobs)
Jobs::new(jobs.into_iter().filter(|t| !t.command.is_empty()).collect())
})
.or_else(|| {
self.components.iter().find_map(|(c_name, component)| {
@ -137,7 +146,7 @@ impl Project {
.flat_map(|jobs| jobs.to_vec())
.collect::<Vec<_>>();
jobs.push(job);
Jobs::new(jobs)
Jobs::new(jobs.into_iter().filter(|t| !t.command.is_empty()).collect())
})
} else {
None
@ -311,7 +320,7 @@ impl Default for Component {
#[derive(Serialize, Deserialize, Default, Clone)]
#[serde(default)]
pub struct TaskDefinition {
pub description: String,
pub description: Option<String>,
/// A map of environment variables that are provided before running the task
pub env: HashMap<String, String>,
/// The command(s) to execute when the task is launched
@ -329,6 +338,7 @@ impl From<&TaskDefinition> for Job {
command: source.command.clone(),
retry: false,
keep_alive: false,
path: source.path.clone().unwrap_or_else(|| String::from(".")),
retry_delay: 0,
..Default::default()
}

View File

@ -2,7 +2,7 @@ use std::{collections::HashMap, fmt::Display};
use ansi_term::Color;
use crate::definition::{Group, Project};
use crate::definition::{Group, Project, TaskDefinition};
pub fn header<T: Into<String>>(name: T, msg: &str) {
let text = format!(" - --=[ {: <20} {: >20} ]=-- -", name.into(), msg);
@ -50,12 +50,13 @@ pub fn item_list(project: &Project) {
if project.tasks.is_empty() && project.components.values().all(|c| c.tasks.is_empty()) {
println!("{}", Color::White.dimmed().paint("no tasks defined"));
} else {
for (name, _tasks) in sort_map(&project.tasks).iter() {
println!("{}", name);
for (name, task) in sort_map(&project.tasks).iter() {
print_task(name, task);
}
for (c_name, component) in sort_map(&project.components).iter() {
for (t_name, _tasks) in sort_map(&component.tasks).iter() {
println!("{}:{}", c_name, t_name);
for (t_name, task) in sort_map(&component.tasks).iter() {
print_task(&format!("{}:{}", c_name, t_name), task);
}
}
}
@ -70,6 +71,14 @@ where
items
}
fn print_task(name: &str, task: &TaskDefinition) {
if let Some(ref desc) = task.description {
println!("{: <31}{}", name, desc);
} else {
println!("{}", name);
}
}
fn print_group(name: &str, group: &Group) {
if let Some(ref desc) = group.description {
println!("{: <31}{}", name, desc);