Skip to content

Commit 6e59d53

Browse files
committed
feat: cli history
1 parent 404d140 commit 6e59d53

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

file_classification_cli/src/bin/file_classification_cli.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ fn run_repl(conn: &mut AnyConnection, context: &mut Context) -> Result<(), Box<d
551551
let mut rl = DefaultEditor::new()?;
552552
println!("欢迎来到文件分类 REPL 环境!");
553553
println!("输入 'help' 查看可用命令,输入 'exit' 或 'quit' 退出。");
554-
554+
555555
// 尝试加载历史记录
556556
let history_path = std::path::Path::new(".file_classification_history");
557557
if history_path.exists() {
@@ -569,18 +569,18 @@ fn run_repl(conn: &mut AnyConnection, context: &mut Context) -> Result<(), Box<d
569569
},
570570
},
571571
};
572-
572+
573573
let readline = rl.readline(&prompt);
574574
match readline {
575575
Ok(line) => {
576576
let line = line.trim();
577577
if line.is_empty() {
578578
continue;
579579
}
580-
580+
581581
// 添加到历史记录
582582
let _ = rl.add_history_entry(line);
583-
583+
584584
if line == "exit" || line == "quit" {
585585
break;
586586
}
@@ -616,25 +616,6 @@ fn run_repl(conn: &mut AnyConnection, context: &mut Context) -> Result<(), Box<d
616616
}
617617
continue;
618618
}
619-
if line == "context" {
620-
print_context(context);
621-
continue;
622-
}
623-
if line == "clear" {
624-
print!("\x1B[2J\x1B[1;1H"); // 清屏
625-
continue;
626-
}
627-
if line.starts_with("!") && line.len() > 1 {
628-
// 执行系统命令
629-
let cmd = &line[1..];
630-
match std::process::Command::new("cmd")
631-
.args(&["/C", cmd])
632-
.status() {
633-
Ok(_) => {},
634-
Err(e) => eprintln!("执行系统命令失败: {}", e),
635-
}
636-
continue;
637-
}
638619

639620
let args = shlex::split(line).unwrap_or_default();
640621
let cli_args = std::iter::once("file_classification_cli".to_string()).chain(args);
@@ -665,6 +646,9 @@ fn run_repl(conn: &mut AnyConnection, context: &mut Context) -> Result<(), Box<d
665646
}
666647
}
667648
}
649+
650+
// 保存历史记录
651+
let _ = rl.save_history(history_path);
668652
Ok(())
669653
}
670654

@@ -856,7 +840,7 @@ fn handle_command(command: Cli, conn: &mut AnyConnection, context: &mut Context)
856840
input.trim().to_string()
857841
});
858842

859-
match groups::create_group(conn, &name) {
843+
match groups::create_group_by_name(conn, &name) {
860844
Ok(count) => println!("成功创建组,影响 {} 行", count),
861845
Err(e) => eprintln!("创建组失败: {:?}", e),
862846
}
@@ -989,7 +973,7 @@ fn handle_command(command: Cli, conn: &mut AnyConnection, context: &mut Context)
989973
input.trim().to_string()
990974
});
991975

992-
match tags::create_tag(conn, &name) {
976+
match tags::create_tag_by_name(conn, &name) {
993977
Ok(tag) => println!("成功创建标签: {:?}", tag),
994978
Err(e) => eprintln!("创建标签失败: {:?}", e),
995979
}

0 commit comments

Comments
 (0)