fix: make id mandatory for delete and optional for get/info
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -55,7 +55,6 @@ pub struct ModeArgs {
|
|||||||
#[arg(help(
|
#[arg(help(
|
||||||
"Get an item either by it's ID or by a combination of matching tags and metatdata"
|
"Get an item either by it's ID or by a combination of matching tags and metatdata"
|
||||||
))]
|
))]
|
||||||
#[arg(requires = "ids_or_tags")]
|
|
||||||
pub info: bool,
|
pub info: bool,
|
||||||
|
|
||||||
#[arg(group("mode"), help_heading("Mode Options"), short('S'), long, conflicts_with_all(["save", "get", "diff", "list", "delete", "info", "server"]))]
|
#[arg(group("mode"), help_heading("Mode Options"), short('S'), long, conflicts_with_all(["save", "get", "diff", "list", "delete", "info", "server"]))]
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ pub fn mode_get(
|
|||||||
conn: &mut rusqlite::Connection,
|
conn: &mut rusqlite::Connection,
|
||||||
data_path: PathBuf,
|
data_path: PathBuf,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if !ids.is_empty() && !tags.is_empty() {
|
if ids.is_empty() && tags.is_empty() {
|
||||||
|
cmd.error(clap::error::ErrorKind::InvalidValue, "No ID or tags given, you must supply exactly one ID or at least one tag when using --get").exit();
|
||||||
|
} else if !ids.is_empty() && !tags.is_empty() {
|
||||||
cmd.error(clap::error::ErrorKind::InvalidValue, "Both ID and tags given, you must supply exactly one ID or at least one tag when using --get").exit();
|
cmd.error(clap::error::ErrorKind::InvalidValue, "Both ID and tags given, you must supply exactly one ID or at least one tag when using --get").exit();
|
||||||
} else if ids.len() > 1 {
|
} else if ids.len() > 1 {
|
||||||
cmd.error(clap::error::ErrorKind::InvalidValue, "More than one ID given, you must supply exactly one ID or at least one tag when using --get").exit();
|
cmd.error(clap::error::ErrorKind::InvalidValue, "More than one ID given, you must supply exactly one ID or at least one tag when using --get").exit();
|
||||||
|
|||||||
@@ -25,16 +25,21 @@ pub fn mode_info(
|
|||||||
data_path: PathBuf,
|
data_path: PathBuf,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// For --info, we only use IDs, tags should be empty
|
// For --info, we only use IDs, tags should be empty
|
||||||
if ids.is_empty() {
|
if ids.is_empty() && !_tags.is_empty() {
|
||||||
cmd.error(ErrorKind::InvalidValue, "No ID provided for --info").exit();
|
cmd.error(ErrorKind::InvalidValue, "Tags are not supported for --info, only IDs").exit();
|
||||||
} else if ids.len() > 1 {
|
} else if ids.len() > 1 {
|
||||||
cmd.error(ErrorKind::InvalidValue, "More than one ID given, you must supply exactly one ID when using --info").exit();
|
cmd.error(ErrorKind::InvalidValue, "More than one ID given, you must supply exactly one ID when using --info").exit();
|
||||||
|
} else if ids.is_empty() {
|
||||||
|
// If no ID is provided, find the last item
|
||||||
|
// This matches the behavior in find_item when (true, true)
|
||||||
|
// Clear the ids vector to ensure find_item uses the last item
|
||||||
|
ids.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
let item_service = ItemService::new(data_path.clone());
|
let item_service = ItemService::new(data_path.clone());
|
||||||
// Use empty tags vector since --info only works with IDs
|
// Use empty tags vector since --info only works with IDs
|
||||||
let item_with_meta = item_service
|
let item_with_meta = item_service
|
||||||
.find_item(conn, ids, &Vec::new(), &std::collections::HashMap::new())
|
.find_item(conn, ids, _tags, &std::collections::HashMap::new())
|
||||||
.map_err(|e| anyhow!("Unable to find matching item in database: {}", e))?;
|
.map_err(|e| anyhow!("Unable to find matching item in database: {}", e))?;
|
||||||
|
|
||||||
show_item(item_with_meta, settings, data_path)
|
show_item(item_with_meta, settings, data_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user