Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion scripts/test-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set -e
cp target/release/oseda test



cd test


Expand Down
36 changes: 19 additions & 17 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use inquire::validator::Validation;
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;

use crate::categories::Category;
use crate::tags::Tag;
use crate::cmd::check::OsedaCheckError;
use crate::color::Color;
use crate::github;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn validate_config(
pub struct OsedaConfig {
pub title: String,
pub author: String,
pub category: Vec<Category>,
pub tags: Vec<Tag>,
// effectively mutable. Will get updated on each deployment
pub last_updated: DateTime<Utc>,
pub color: String,
Expand Down Expand Up @@ -132,7 +132,7 @@ pub fn create_conf() -> Result<OsedaConfig, Box<dyn Error>> {

title = title.replace(" ", "-");

let categories = get_categories()?;
let tags = get_tags()?;
let color = get_color()?;

let user_name = github::get_config_from_user_git("user.name")
Expand All @@ -141,7 +141,7 @@ pub fn create_conf() -> Result<OsedaConfig, Box<dyn Error>> {
Ok(OsedaConfig {
title: title.trim().to_owned(),
author: user_name,
category: categories,
tags,
last_updated: get_time(),
color: color.into_hex(),
})
Expand All @@ -150,21 +150,23 @@ pub fn create_conf() -> Result<OsedaConfig, Box<dyn Error>> {
/// Prompts user for categories associated with their Oseda project
///
/// # Returns
/// * `Ok(Vec<Category>)` with selected categories
/// * `Ok(Vec<Tag>)` with selected categories
/// * `Err` if the prompting went wrong somewhere
fn get_categories() -> Result<Vec<Category>, Box<dyn Error>> {
let options: Vec<Category> = Category::iter().collect();
fn get_tags() -> Result<Vec<Tag>, Box<dyn Error>> {
let options: Vec<Tag> = Tag::iter().collect();

let selected_categories =
inquire::MultiSelect::new("Select categories (type to search):", options.clone())
println!("Select tags that match your course's meaning and purpose.");
println!("(You can always add custom tags later!)");
let selected_tags =
inquire::MultiSelect::new("Select tags (type to search):", options.clone())
.prompt()?;

println!("You selected:");
for category in selected_categories.iter() {
println!("- {:?}", category);
for tag in selected_tags.iter() {
println!("- {:?}", tag);
}

Ok(selected_categories)
Ok(selected_tags)
}

fn get_color() -> Result<Color, Box<dyn Error>> {
Expand Down Expand Up @@ -236,7 +238,7 @@ mod test {
{
"title": "TestableRust",
"author": "JaneDoe",
"category": ["ComputerScience"],
"tags": ["ComputerScience"],
"last_updated": "2024-07-10T12:34:56Z"
}
"#
Expand All @@ -258,7 +260,7 @@ mod test {
let conf = OsedaConfig {
title: "my-project".to_string(),
author: "JaneDoe".to_string(),
category: vec![Category::ComputerScience],
tags: vec![Tag::ComputerScience],
last_updated: chrono::Utc::now(),
color: Color::Black.into_hex(),
};
Expand All @@ -275,7 +277,7 @@ mod test {
let conf = OsedaConfig {
title: "my-project".to_string(),
author: "JaneDoe".to_string(),
category: vec![Category::ComputerScience],
tags: vec![Tag::ComputerScience],
last_updated: chrono::Utc::now(),
color: Color::Black.into_hex(),
};
Expand All @@ -292,7 +294,7 @@ mod test {
let conf = OsedaConfig {
title: "correct-name".to_string(),
author: "JaneDoe".to_string(),
category: vec![Category::ComputerScience],
tags: vec![Tag::ComputerScience],
last_updated: chrono::Utc::now(),
color: Color::Black.into_hex(),
};
Expand All @@ -311,7 +313,7 @@ mod test {
let conf = OsedaConfig {
title: "oseda".to_string(),
author: "JaneDoe".to_string(),
category: vec![Category::ComputerScience],
tags: vec![Tag::ComputerScience],
last_updated: chrono::Utc::now(),
color: Color::Black.into_hex(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod categories;
pub mod tags;
pub mod cmd;
pub mod color;
pub mod config;
Expand Down
11 changes: 7 additions & 4 deletions src/categories.rs → src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter};

#[derive(Serialize, Deserialize, Debug, Clone, Copy, Display, EnumIter)]
pub enum Category {
pub enum Tag {
Aerospace,
Business,
ComputerScience,
Expand All @@ -19,10 +19,13 @@ pub enum Category {
Politics,
Psychology,
Science,
// Custom(String),
}
// TODO document me
// Custom tags must be added by hand to the oseda-config.json

impl Category {
pub fn to_vec() -> Vec<Category> {
Category::iter().collect()
impl Tag {
pub fn to_vec() -> Vec<Tag> {
Tag::iter().collect()
}
}
Loading