ent list FILTER: the filter now takes multiple strings
This is instead of a single big string with chunks separated by ":". ":" is used in RFC 3339 date-time strings (like "2025-07-16 21:23:44 -06:00"), so it's inconvenient to reserve ":" to be the chunk separator. I'm not super wedded to this new Vec<String> way of doing the filter, but it seems fine and convenient for now.
This commit is contained in:
parent
5e5508a2ee
commit
20c17f281b
2 changed files with 91 additions and 66 deletions
|
|
@ -24,22 +24,24 @@ struct Args {
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// List issues.
|
/// List issues.
|
||||||
List {
|
List {
|
||||||
/// Filter string, describes issues to include in the list.
|
/// Filter strings, describes issues to include in the list.
|
||||||
/// The filter string is composed of chunks separated by ":".
|
/// Each filter string is of the form "name=condition".
|
||||||
/// Each chunk is of the form "name=condition". The supported
|
/// The supported names and their matching conditions are:
|
||||||
/// names and their matching conditions are:
|
|
||||||
///
|
///
|
||||||
/// "state": Comma-separated list of states to list.
|
/// "state": Comma-separated list of states to list.
|
||||||
|
/// Example: "state=new,backlog". Defaults to
|
||||||
|
/// "new,backlog,blocked,inprogress".
|
||||||
///
|
///
|
||||||
/// "assignee": Comma-separated list of assignees to list.
|
/// "assignee": Comma-separated list of assignees to include in
|
||||||
/// Defaults to all assignees if not set.
|
/// the list. The empty string includes issues with no assignee.
|
||||||
|
/// Example: "assignee=seb," lists issues assigned to "seb" and
|
||||||
|
/// issues without an assignee. Defaults to include all issues.
|
||||||
///
|
///
|
||||||
/// "tag": Comma-separated list of tags to include or exclude
|
/// "tag": Comma-separated list of tags to include, or exclude
|
||||||
/// (if prefixed with "-"). If omitted, defaults to including
|
/// if prefixed with "-". Example: "tag=bug,-docs" shows issues
|
||||||
/// all tags and excluding none.
|
/// that are tagged "bug" and not tagged "docs". Defaults to
|
||||||
///
|
/// including all tags and excluding none.
|
||||||
#[arg(default_value_t = String::from("state=New,Backlog,Blocked,InProgress"))]
|
filter: Vec<String>,
|
||||||
filter: String,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Create a new issue.
|
/// Create a new issue.
|
||||||
|
|
@ -93,7 +95,14 @@ fn handle_command(
|
||||||
match &args.command {
|
match &args.command {
|
||||||
Commands::List { filter } => {
|
Commands::List { filter } => {
|
||||||
let issues = entomologist::database::read_issues_database(issues_database_source)?;
|
let issues = entomologist::database::read_issues_database(issues_database_source)?;
|
||||||
let filter = entomologist::Filter::new_from_str(filter)?;
|
let filter = {
|
||||||
|
let mut f = entomologist::Filter::new();
|
||||||
|
for filter_str in filter {
|
||||||
|
f.parse(filter_str)?;
|
||||||
|
}
|
||||||
|
f
|
||||||
|
};
|
||||||
|
|
||||||
let mut uuids_by_state = std::collections::HashMap::<
|
let mut uuids_by_state = std::collections::HashMap::<
|
||||||
entomologist::issue::State,
|
entomologist::issue::State,
|
||||||
Vec<&entomologist::issue::IssueHandle>,
|
Vec<&entomologist::issue::IssueHandle>,
|
||||||
|
|
@ -191,8 +200,10 @@ fn handle_command(
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::New { description } => {
|
Commands::New { description } => {
|
||||||
let issues_database =
|
let issues_database = entomologist::database::make_issues_database(
|
||||||
entomologist::database::make_issues_database(issues_database_source, entomologist::database::IssuesDatabaseAccess::ReadWrite)?;
|
issues_database_source,
|
||||||
|
entomologist::database::IssuesDatabaseAccess::ReadWrite,
|
||||||
|
)?;
|
||||||
match entomologist::issue::Issue::new(&issues_database.dir, description) {
|
match entomologist::issue::Issue::new(&issues_database.dir, description) {
|
||||||
Err(entomologist::issue::IssueError::EmptyDescription) => {
|
Err(entomologist::issue::IssueError::EmptyDescription) => {
|
||||||
println!("no new issue created");
|
println!("no new issue created");
|
||||||
|
|
@ -209,8 +220,10 @@ fn handle_command(
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Edit { uuid } => {
|
Commands::Edit { uuid } => {
|
||||||
let issues_database =
|
let issues_database = entomologist::database::make_issues_database(
|
||||||
entomologist::database::make_issues_database(issues_database_source, entomologist::database::IssuesDatabaseAccess::ReadWrite)?;
|
issues_database_source,
|
||||||
|
entomologist::database::IssuesDatabaseAccess::ReadWrite,
|
||||||
|
)?;
|
||||||
let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?;
|
let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?;
|
||||||
if let Some(issue) = issues.get_mut_issue(uuid) {
|
if let Some(issue) = issues.get_mut_issue(uuid) {
|
||||||
match issue.edit_description() {
|
match issue.edit_description() {
|
||||||
|
|
@ -279,8 +292,10 @@ fn handle_command(
|
||||||
new_state,
|
new_state,
|
||||||
} => match new_state {
|
} => match new_state {
|
||||||
Some(new_state) => {
|
Some(new_state) => {
|
||||||
let issues_database =
|
let issues_database = entomologist::database::make_issues_database(
|
||||||
entomologist::database::make_issues_database(issues_database_source, entomologist::database::IssuesDatabaseAccess::ReadWrite)?;
|
issues_database_source,
|
||||||
|
entomologist::database::IssuesDatabaseAccess::ReadWrite,
|
||||||
|
)?;
|
||||||
let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?;
|
let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?;
|
||||||
match issues.issues.get_mut(issue_id) {
|
match issues.issues.get_mut(issue_id) {
|
||||||
Some(issue) => {
|
Some(issue) => {
|
||||||
|
|
@ -312,8 +327,10 @@ fn handle_command(
|
||||||
issue_id,
|
issue_id,
|
||||||
description,
|
description,
|
||||||
} => {
|
} => {
|
||||||
let issues_database =
|
let issues_database = entomologist::database::make_issues_database(
|
||||||
entomologist::database::make_issues_database(issues_database_source, entomologist::database::IssuesDatabaseAccess::ReadWrite)?;
|
issues_database_source,
|
||||||
|
entomologist::database::IssuesDatabaseAccess::ReadWrite,
|
||||||
|
)?;
|
||||||
let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?;
|
let mut issues = entomologist::issues::Issues::new_from_dir(&issues_database.dir)?;
|
||||||
let Some(issue) = issues.get_mut_issue(issue_id) else {
|
let Some(issue) = issues.get_mut_issue(issue_id) else {
|
||||||
return Err(anyhow::anyhow!("issue {} not found", issue_id));
|
return Err(anyhow::anyhow!("issue {} not found", issue_id));
|
||||||
|
|
@ -338,9 +355,13 @@ fn handle_command(
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Sync { remote } => {
|
Commands::Sync { remote } => {
|
||||||
if let entomologist::database::IssuesDatabaseSource::Branch(branch) = issues_database_source {
|
if let entomologist::database::IssuesDatabaseSource::Branch(branch) =
|
||||||
let issues_database =
|
issues_database_source
|
||||||
entomologist::database::make_issues_database(issues_database_source, entomologist::database::IssuesDatabaseAccess::ReadWrite)?;
|
{
|
||||||
|
let issues_database = entomologist::database::make_issues_database(
|
||||||
|
issues_database_source,
|
||||||
|
entomologist::database::IssuesDatabaseAccess::ReadWrite,
|
||||||
|
)?;
|
||||||
entomologist::git::sync(&issues_database.dir, remote, branch)?;
|
entomologist::git::sync(&issues_database.dir, remote, branch)?;
|
||||||
println!("synced {:?} with {:?}", branch, remote);
|
println!("synced {:?} with {:?}", branch, remote);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -440,7 +461,9 @@ fn main() -> anyhow::Result<()> {
|
||||||
// println!("{:?}", args);
|
// println!("{:?}", args);
|
||||||
|
|
||||||
let issues_database_source = match (&args.issues_dir, &args.issues_branch) {
|
let issues_database_source = match (&args.issues_dir, &args.issues_branch) {
|
||||||
(Some(dir), None) => entomologist::database::IssuesDatabaseSource::Dir(std::path::Path::new(dir)),
|
(Some(dir), None) => {
|
||||||
|
entomologist::database::IssuesDatabaseSource::Dir(std::path::Path::new(dir))
|
||||||
|
}
|
||||||
(None, Some(branch)) => entomologist::database::IssuesDatabaseSource::Branch(branch),
|
(None, Some(branch)) => entomologist::database::IssuesDatabaseSource::Branch(branch),
|
||||||
(None, None) => entomologist::database::IssuesDatabaseSource::Branch("entomologist-data"),
|
(None, None) => entomologist::database::IssuesDatabaseSource::Branch("entomologist-data"),
|
||||||
(Some(_), Some(_)) => {
|
(Some(_), Some(_)) => {
|
||||||
|
|
|
||||||
84
src/lib.rs
84
src/lib.rs
|
|
@ -1,10 +1,12 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
|
pub mod database;
|
||||||
pub mod git;
|
pub mod git;
|
||||||
pub mod issue;
|
pub mod issue;
|
||||||
pub mod issues;
|
pub mod issues;
|
||||||
pub mod database;
|
|
||||||
|
use crate::issue::State;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum ParseFilterError {
|
pub enum ParseFilterError {
|
||||||
|
|
@ -26,9 +28,8 @@ pub struct Filter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Filter<'a> {
|
impl<'a> Filter<'a> {
|
||||||
pub fn new_from_str(filter_str: &'a str) -> Result<Filter<'a>, ParseFilterError> {
|
pub fn new() -> Filter<'a> {
|
||||||
use crate::issue::State;
|
Self {
|
||||||
let mut f = Filter {
|
|
||||||
include_states: std::collections::HashSet::<crate::issue::State>::from([
|
include_states: std::collections::HashSet::<crate::issue::State>::from([
|
||||||
State::InProgress,
|
State::InProgress,
|
||||||
State::Blocked,
|
State::Blocked,
|
||||||
|
|
@ -38,51 +39,52 @@ impl<'a> Filter<'a> {
|
||||||
include_assignees: std::collections::HashSet::<&'a str>::new(),
|
include_assignees: std::collections::HashSet::<&'a str>::new(),
|
||||||
include_tags: std::collections::HashSet::<&'a str>::new(),
|
include_tags: std::collections::HashSet::<&'a str>::new(),
|
||||||
exclude_tags: std::collections::HashSet::<&'a str>::new(),
|
exclude_tags: std::collections::HashSet::<&'a str>::new(),
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for filter_chunk_str in filter_str.split(":") {
|
pub fn parse(&mut self, filter_str: &'a str) -> Result<(), ParseFilterError> {
|
||||||
let tokens: Vec<&str> = filter_chunk_str.split("=").collect();
|
let tokens: Vec<&str> = filter_str.split("=").collect();
|
||||||
if tokens.len() != 2 {
|
if tokens.len() != 2 {
|
||||||
return Err(ParseFilterError::ParseError);
|
return Err(ParseFilterError::ParseError);
|
||||||
|
}
|
||||||
|
|
||||||
|
match tokens[0] {
|
||||||
|
"state" => {
|
||||||
|
self.include_states.clear();
|
||||||
|
for s in tokens[1].split(",") {
|
||||||
|
self.include_states
|
||||||
|
.insert(crate::issue::State::from_str(s)?);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match tokens[0] {
|
"assignee" => {
|
||||||
"state" => {
|
self.include_assignees.clear();
|
||||||
f.include_states.clear();
|
for s in tokens[1].split(",") {
|
||||||
for s in tokens[1].split(",") {
|
self.include_assignees.insert(s);
|
||||||
f.include_states.insert(crate::issue::State::from_str(s)?);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"tag" => {
|
||||||
|
self.include_tags.clear();
|
||||||
|
self.exclude_tags.clear();
|
||||||
|
for s in tokens[1].split(",") {
|
||||||
|
if s.len() == 0 {
|
||||||
|
return Err(ParseFilterError::ParseError);
|
||||||
|
}
|
||||||
|
if s.chars().nth(0).unwrap() == '-' {
|
||||||
|
self.exclude_tags.insert(&s[1..]);
|
||||||
|
} else {
|
||||||
|
self.include_tags.insert(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"assignee" => {
|
_ => {
|
||||||
f.include_assignees.clear();
|
println!("unknown filter string '{}'", filter_str);
|
||||||
for s in tokens[1].split(",") {
|
return Err(ParseFilterError::ParseError);
|
||||||
f.include_assignees.insert(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"tag" => {
|
|
||||||
f.include_tags.clear();
|
|
||||||
f.exclude_tags.clear();
|
|
||||||
for s in tokens[1].split(",") {
|
|
||||||
if s.len() == 0 {
|
|
||||||
return Err(ParseFilterError::ParseError);
|
|
||||||
}
|
|
||||||
if s.chars().nth(0).unwrap() == '-' {
|
|
||||||
f.exclude_tags.insert(&s[1..]);
|
|
||||||
} else {
|
|
||||||
f.include_tags.insert(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {
|
|
||||||
println!("unknown filter chunk '{}'", filter_chunk_str);
|
|
||||||
return Err(ParseFilterError::ParseError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(f)
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue