diff --git a/Cargo.toml b/Cargo.toml index c017ff3..ba3bd7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,3 @@ version = "0.1.0" edition = "2024" [dependencies] -anyhow = "1.0.95" -clap = { version = "4.5.26", features = ["derive"] } -serde = { version = "1.0.217", features = ["derive"] } -thiserror = "2.0.11" -toml = "0.8.19" diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs deleted file mode 100644 index 238bbe3..0000000 --- a/src/bin/ent/main.rs +++ /dev/null @@ -1,44 +0,0 @@ -use clap::Parser; - -#[derive(Debug, clap::Parser)] -#[command(version, about, long_about = None)] -struct Args { - /// Directory containing issues. - #[arg(short, long)] - issues_dir: String, - - /// Type of behavior/output. - #[command(subcommand)] - command: Commands, -} - -#[derive(clap::Subcommand, Debug)] -enum Commands { - /// List issues. - List, - // Mdbook { - // /// The name of the recipe to create MD Book for. - // target: String, - // }, - // Info { - // /// The name of the recipe to show info for. - // target: String, - // }, -} - -fn main() -> anyhow::Result<()> { - let args: Args = Args::parse(); - // println!("{:?}", args); - - match args.command { - Commands::List => { - let issues = - entomologist::issues::Issues::new_from_dir(std::path::Path::new(&args.issues_dir))?; - for (uuid, issue) in issues.issues.iter() { - println!("{} {} ({:?})", uuid, issue.title, issue.state); - } - } - } - - Ok(()) -} diff --git a/src/issue.rs b/src/issue.rs deleted file mode 100644 index 6dde005..0000000 --- a/src/issue.rs +++ /dev/null @@ -1,109 +0,0 @@ -use std::str::FromStr; - -#[derive(Debug, PartialEq, serde::Deserialize)] -/// These are the states an issue can be in. -pub enum State { - New, - Backlog, - InProgress, - Done, - WontDo, -} - -#[derive(Debug, PartialEq)] -pub struct Issue { - pub title: String, - pub description: Option, - pub state: State, -} - -#[derive(Debug, thiserror::Error)] -pub enum ReadIssueError { - #[error(transparent)] - StdIoError(#[from] std::io::Error), - #[error("Failed to parse issue")] - IssueParseError, -} - -impl FromStr for State { - type Err = ReadIssueError; - fn from_str(s: &str) -> Result { - let s = s.to_lowercase(); - if s == "new" { - Ok(State::New) - } else if s == "backlog" { - Ok(State::Backlog) - } else if s == "inprogress" { - Ok(State::InProgress) - } else if s == "done" { - Ok(State::Done) - } else if s == "wontdo" { - Ok(State::WontDo) - } else { - Err(ReadIssueError::IssueParseError) - } - } -} - -impl Issue { - pub fn new_from_dir(dir: &std::path::Path) -> Result { - let mut title: Option = None; - let mut description: Option = None; - let mut state = State::New; // default state, if not specified in the issue - - for direntry in dir.read_dir()? { - if let Ok(direntry) = direntry { - let file_name = direntry.file_name(); - if file_name == "title" { - title = Some(std::fs::read_to_string(direntry.path())?.trim().into()); - } else if file_name == "description" { - description = Some(std::fs::read_to_string(direntry.path())?); - } else if file_name == "state" { - let state_string = std::fs::read_to_string(direntry.path())?; - state = State::from_str(state_string.trim())?; - } else { - println!("ignoring unknown file in issue directory: {:?}", file_name); - } - } - } - - if title == None { - return Err(ReadIssueError::IssueParseError); - } - - Ok(Self { - title: title.unwrap(), - description: description, - state: state, - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn read_issue_0() { - let issue_dir = std::path::Path::new("test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/"); - let issue = Issue::new_from_dir(issue_dir).unwrap(); - let expected = Issue { - title: String::from("this is the title of my issue"), - description: Some(String::from("This is the description of my issue.\nIt is multiple lines.\n* Arbitrary contents\n* But let's use markdown by convention\n")), - state: State::New, - }; - assert_eq!(issue, expected); - } - - #[test] - fn read_issue_1() { - let issue_dir = std::path::Path::new("test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/"); - let issue = Issue::new_from_dir(issue_dir).unwrap(); - let expected = Issue { - title: String::from("minimal"), - description: None, - state: State::InProgress, - }; - assert_eq!(issue, expected); - } -} diff --git a/src/issues.rs b/src/issues.rs deleted file mode 100644 index b5c1c87..0000000 --- a/src/issues.rs +++ /dev/null @@ -1,125 +0,0 @@ -// Just a placeholder for now, get rid of this if we don't need it. -#[derive(Debug, PartialEq, serde::Deserialize)] -pub struct Config {} - -#[derive(Debug, PartialEq)] -pub struct Issues { - pub issues: std::collections::HashMap, - pub config: Config, -} - -#[derive(Debug, thiserror::Error)] -pub enum ReadIssuesError { - #[error(transparent)] - StdIoError(#[from] std::io::Error), - #[error("Failed to parse issue")] - IssueParseError(#[from] crate::issue::ReadIssueError), - #[error("cannot handle filename")] - FilenameError(std::ffi::OsString), - #[error(transparent)] - TomlDeserializeError(#[from] toml::de::Error), -} - -impl Issues { - pub fn new() -> Self { - Self { - issues: std::collections::HashMap::new(), - config: Config {}, - } - } - - pub fn add_issue(&mut self, uuid: String, issue: crate::issue::Issue) { - self.issues.insert(uuid, issue); - } - - fn parse_config(&mut self, config_path: &std::path::Path) -> Result<(), ReadIssuesError> { - let config_contents = std::fs::read_to_string(config_path)?; - let config: Config = toml::from_str(&config_contents)?; - self.config = config; - Ok(()) - } - - pub fn new_from_dir(dir: &std::path::Path) -> Result { - let mut issues = Self::new(); - - for direntry in dir.read_dir()? { - if let Ok(direntry) = direntry { - if direntry.metadata()?.is_dir() { - let uuid = match direntry.file_name().into_string() { - Ok(uuid) => uuid, - Err(orig_string) => { - return Err(ReadIssuesError::FilenameError(orig_string)) - } - }; - let issue = crate::issue::Issue::new_from_dir(direntry.path().as_path())?; - issues.add_issue(uuid, issue); - } else if direntry.file_name() == "config.toml" { - issues.parse_config(direntry.path().as_path())?; - } else { - println!( - "ignoring unknown file in issues directory: {:?}", - direntry.file_name() - ); - } - } - } - return Ok(issues); - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn read_issues_0000() { - let issues_dir = std::path::Path::new("test/0000/"); - let issues = Issues::new_from_dir(issues_dir).unwrap(); - - let mut expected = Issues::new(); - expected.add_issue( - String::from("7792b063eef6d33e7da5dc1856750c149ba678c6"), - crate::issue::Issue { - title: String::from("minimal"), - description: None, - state: crate::issue::State::InProgress, - }, - ); - expected.add_issue( - String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f"), - crate::issue::Issue { - title: String::from("this is the title of my issue"), - description: Some(String::from("This is the description of my issue.\nIt is multiple lines.\n* Arbitrary contents\n* But let's use markdown by convention\n")), - state: crate::issue::State::New, - } - ); - assert_eq!(issues, expected); - } - - #[test] - fn read_issues_0001() { - let issues_dir = std::path::Path::new("test/0001/"); - let issues = Issues::new_from_dir(issues_dir).unwrap(); - - let mut expected = Issues::new(); - expected.add_issue( - String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), - crate::issue::Issue { - title: String::from("oh yeah we got titles"), - description: None, - state: crate::issue::State::Done, - }, - ); - expected.add_issue( - String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), - crate::issue::Issue { - title: String::from("issues out the wazoo"), - description: Some(String::from( - "Lots of words\nthat don't say much\nbecause this is just\na test\n", - )), - state: crate::issue::State::WontDo, - }, - ); - assert_eq!(issues, expected); - } -} diff --git a/src/lib.rs b/src/lib.rs index 713acd1..8b13789 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1 @@ -pub mod issue; -pub mod issues; + diff --git a/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/description b/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/description deleted file mode 100644 index 3db0fcf..0000000 --- a/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/description +++ /dev/null @@ -1,4 +0,0 @@ -This is the description of my issue. -It is multiple lines. -* Arbitrary contents -* But let's use markdown by convention diff --git a/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/title b/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/title deleted file mode 100644 index c9c2379..0000000 --- a/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/title +++ /dev/null @@ -1 +0,0 @@ -this is the title of my issue diff --git a/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/state b/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/state deleted file mode 100644 index 0737713..0000000 --- a/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/state +++ /dev/null @@ -1 +0,0 @@ -inprogress diff --git a/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/title b/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/title deleted file mode 100644 index dd1a932..0000000 --- a/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/title +++ /dev/null @@ -1 +0,0 @@ -minimal diff --git a/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/state b/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/state deleted file mode 100644 index 19f86f4..0000000 --- a/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/state +++ /dev/null @@ -1 +0,0 @@ -done diff --git a/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/title b/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/title deleted file mode 100644 index 18a1926..0000000 --- a/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/title +++ /dev/null @@ -1 +0,0 @@ -oh yeah we got titles diff --git a/test/0001/config.toml b/test/0001/config.toml deleted file mode 100644 index dfc15f2..0000000 --- a/test/0001/config.toml +++ /dev/null @@ -1 +0,0 @@ -states = [ "open", "closed" ] diff --git a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description deleted file mode 100644 index 010156b..0000000 --- a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description +++ /dev/null @@ -1,4 +0,0 @@ -Lots of words -that don't say much -because this is just -a test diff --git a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/state b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/state deleted file mode 100644 index 7f19192..0000000 --- a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/state +++ /dev/null @@ -1 +0,0 @@ -wontdo diff --git a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title deleted file mode 100644 index ab5b4a9..0000000 --- a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title +++ /dev/null @@ -1 +0,0 @@ -issues out the wazoo