Skip to content

Commit

Permalink
fix(project): use indexmap to load project correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya-zero committed Jul 3, 2024
1 parent 7814ee6 commit 33e1077
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ debug = false
[dependencies]
clap = "4.5.1"
dialoguer = "0.11.0"
indexmap = { version = "2.2.6", features = ["serde"] }
serde = { version = "1.0.196", features = ["derive"] }
serde_yaml = "0.9.31"
thiserror = "1.0.61"
Expand Down
3 changes: 3 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ pub fn args() -> Command {
.subcommand_required(true)
.arg(
Arg::new("project")
.long("project")
.short('p')
.help("Path to the project file.")
.default_value("tesuto.yml")
.hide_default_value(true)
.value_parser(clap::value_parser!(String))
.required(false)
.global(true)
.num_args(1),
)
.subcommands([
Expand Down
20 changes: 10 additions & 10 deletions src/project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use thiserror::Error;

#[derive(Deserialize, Serialize, Clone, Default)]
Expand Down Expand Up @@ -49,10 +49,10 @@ pub struct WithOptions {
#[derive(Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct Project {
name: String,
name: Option<String>,
require: Option<Vec<String>>,
with: Option<WithOptions>,
jobs: BTreeMap<String, Vec<Step>>,
jobs: IndexMap<String, Vec<Step>>,
}

#[derive(Debug, Error)]
Expand All @@ -64,24 +64,24 @@ pub enum ProjectError {
impl Default for Project {
fn default() -> Self {
Self {
name: String::from("TesutoProject"),
name: Some(String::from("TesutoProject")),
require: None,
with: None,
jobs: BTreeMap::new(),
jobs: IndexMap::new(),
}
}
}

impl Project {
pub fn new(name: &str) -> Self {
Self {
name: String::from(name),
name: Some(String::from(name)),
..Default::default()
}
}

pub fn example(name: &str) -> Self {
let mut jobs: BTreeMap<String, Vec<Step>> = BTreeMap::new();
let mut jobs: IndexMap<String, Vec<Step>> = IndexMap::new();
jobs.insert(
"hello".into(),
vec![Step {
Expand All @@ -91,7 +91,7 @@ impl Project {
}],
);
Self {
name: String::from(name),
name: Some(String::from(name)),
jobs,
..Default::default()
}
Expand All @@ -105,10 +105,10 @@ impl Project {
}

pub fn get_name(&self) -> String {
self.name.clone()
self.name.clone().unwrap_or_default()
}

pub fn get_jobs(&self) -> BTreeMap<String, Vec<Step>> {
pub fn get_jobs(&self) -> IndexMap<String, Vec<Step>> {
self.jobs.clone()
}

Expand Down

0 comments on commit 33e1077

Please sign in to comment.