Version 2.0.1 (#4)
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

Reviewed-on: #4
pull/5/head
Joe Bellus 4 months ago
parent 43af1fd35d
commit eaca3f2d4b

2
Cargo.lock generated

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

@ -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

@ -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()
}
@ -458,8 +468,7 @@ mod tests {
assert_eq!(jobs.get(0).unwrap().name, "ui:build-ui");
assert_eq!(jobs.get(1).unwrap().name, "server:setup");
assert_eq!(jobs.get(2).unwrap().name, "server:build");
assert_eq!(jobs.get(3).unwrap().name, "build");
assert_eq!(jobs.len(), 4);
assert_eq!(jobs.len(), 3);
}
#[test]

@ -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);

Loading…
Cancel
Save