Skip to content

Commit

Permalink
simplify sorting of subcommands a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLaPiana committed Feb 10, 2024
1 parent ba1f291 commit 1ef672c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
16 changes: 11 additions & 5 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Contains the Structs for the Schema of the Roxfile
//! as well as the validation logic.
use crate::logs;
use crate::modules::execution::model_injection::{
inject_pipeline_metadata, inject_task_metadata, inject_template_values,
};
use crate::modules::execution::model_injection::{inject_task_metadata, inject_template_values};
use crate::modules::execution::output;
use crate::utils::{color_print, ColorEnum};
use anyhow::Result;
Expand Down Expand Up @@ -219,7 +217,6 @@ pub struct RoxFile {
pub tasks: Vec<Task>,
pub pipelines: Option<Vec<Pipeline>>,
pub templates: Option<Vec<Template>>,
pub additional_files: Option<Vec<String>>,
}

impl RoxFile {
Expand Down Expand Up @@ -259,7 +256,16 @@ impl RoxFile {
.collect();

// Pipelines
roxfile.pipelines = inject_pipeline_metadata(roxfile.pipelines);
if let Some(mut sorted_pipelines) = roxfile.pipelines {
sorted_pipelines.sort_by(|x, y| x.name.to_lowercase().cmp(&y.name.to_lowercase()));
roxfile.pipelines = Some(sorted_pipelines)
}

// Docs
if let Some(mut sorted_docs) = roxfile.docs {
sorted_docs.sort_by(|x, y| x.name.to_lowercase().cmp(&y.name.to_lowercase()));
roxfile.docs = Some(sorted_docs)
}

Ok(roxfile)
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub async fn display_ci_status(ci_info: CiInfo) {
.expect("Failed to retrieve workflow data!")
.into_iter()
.next()
.unwrap();
.expect("Failed to retrieve workflow!");

let results: Vec<RunResult> = workflow_instance
.list_jobs(workflow.id)
Expand All @@ -144,7 +144,7 @@ pub async fn display_ci_status(ci_info: CiInfo) {
.filter(Filter::All)
.send()
.await
.unwrap()
.expect("Failed to retrieve CI results!")
.into_iter()
.flat_map(|job| {
let results: Vec<RunResult> = job
Expand Down
11 changes: 0 additions & 11 deletions src/modules/execution/model_injection.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
use crate::models;

/// Inject additional metadata into each Pipeline and sort based on name.
pub fn inject_pipeline_metadata(
pipelines: Option<Vec<models::Pipeline>>,
) -> Option<Vec<models::Pipeline>> {
if let Some(mut some_pipelines) = pipelines {
some_pipelines.sort_by(|x, y| x.name.to_lowercase().cmp(&y.name.to_lowercase()));
return Some(some_pipelines);
}
pipelines
}

/// Get used Template's information and inject set values
pub fn inject_template_values(mut task: models::Task, template: &models::Template) -> models::Task {
task.command = {
Expand Down

0 comments on commit 1ef672c

Please sign in to comment.