1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
mod browser;
mod cli;
mod config;
mod deduplication;
mod exporter;
mod graph;
mod graph_output;
mod organization;
mod processor;
mod search;
mod utils;
use exporter::export_data;
use search::{open_bookmark, search_bookmarks};
#[derive(Parser)]
#[command(name = "bookmark")]
#[command(about = "Import, search, and manage bookmarks from all browsers", version = "0.1.1")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Export bookmarks/history from browsers
Export {
/// Browser (chrome, firefox, safari, edge, all)
#[arg(short, long, default_value = "all")]
browser: String,
/// Data type (bookmarks, history, both)
#[arg(short, long, default_value = "bookmarks")]
data_type: String,
/// Output directory
#[arg(short, long)]
output: Option<PathBuf>,
/// Custom browser data directory
#[arg(long)]
profile_dir: Option<PathBuf>,
},
/// List available browsers
List {
/// Filter by specific browser
browser: Option<String>,
},
/// Search bookmarks
Search {
/// Search query
query: String,
/// Search in title only
#[arg(long)]
title_only: bool,
/// Search in URL only
#[arg(long)]
url_only: bool,
/// Limit results
#[arg(short, long, default_value = "20")]
limit: usize,
},
/// Open bookmark in browser
Open {
/// Search query
query: String,
/// Open first match without asking
#[arg(short, long)]
first: bool,
},
/// Process bookmarks (deduplicate, organize, or both)
Process {
/// Input file
#[arg(short, long)]
input: PathBuf,
/// Output file
#[arg(short, long)]
output: PathBuf,
/// Processing mode (dedupe, organize, both)
#[arg(short, long, default_value = "both")]
mode: String,
/// Merge strategy (first, last, recent, merge)
#[arg(long, default_value = "merge")]
strategy: String,
/// Organization strategy (domain, category, custom)
#[arg(long, default_value = "custom")]
org_strategy: String,
/// Preview without applying
#[arg(long)]
preview: bool,
/// Create backup
#[arg(long)]
backup: bool,
},
/// Generate knowledge graph
Graph {
/// Browser source
#[arg(short, long, default_value = "all")]
browser: String,
/// Data type (bookmarks, history, both)
#[arg(short, long, default_value = "both")]
data_type: String,
/// Output format (dot, json, gexf, html)
#[arg(short, long, default_value = "html")]
format: String,
/// Output file
#[arg(short, long)]
output: PathBuf,
/// Minimum bookmarks for domain node (default: 5)
#[arg(long, default_value = "5")]
min_threshold: usize,
/// Detail level: overview, standard, detailed
#[arg(long, default_value = "standard")]
detail: String,
/// Maximum bookmarks per domain (for standard detail level)
#[arg(long)]
max_per_domain: Option<usize>,
/// Maximum total bookmarks
#[arg(long)]
max_total: Option<usize>,
/// Domain-only mode (no individual bookmark nodes)
#[arg(long)]
domain_only: bool,
/// Only include bookmarks newer than this date (ISO 8601 format)
#[arg(long)]
since: Option<String>,
},
/// Manage configuration
Config {
/// Show current config
#[arg(long)]
show: bool,
/// Create sample config
#[arg(long)]
create_sample: Option<PathBuf>,
/// List custom rules
#[arg(long)]
list_rules: bool,
},
}
fn main() -> Result<()> {
env_logger::init();
let args = Cli::parse();
match args.command {
Commands::Export {
browser,
data_type,
output,
profile_dir,
} => {
if browser == "all" {
cli::export_all_browsers(&data_type, output, profile_dir)?;
} else {
export_data(&browser, &data_type, output, profile_dir)?;
}
}
Commands::List { browser } => {
if let Some(b) = browser {
cli::list_browser_profiles(&b)?;
} else {
cli::list_all_browsers()?;
}
}
Commands::Search {
query,
title_only,
url_only,
limit,
} => {
search_bookmarks(&query, title_only, url_only, limit)?;
}
Commands::Open { query, first } => {
open_bookmark(&query, first)?;
}
Commands::Process {
input,
output,
mode,
strategy,
org_strategy,
preview,
backup,
} => {
cli::process_bookmarks(&input, &output, &mode, &strategy, &org_strategy, preview, backup)?;
}
Commands::Graph {
browser,
data_type,
format,
output,
min_threshold,
detail,
max_per_domain,
max_total,
domain_only,
since,
} => {
let params = cli::GraphParams {
min_threshold,
detail,
max_per_domain,
max_total,
domain_only,
since,
};
cli::generate_graph(&browser, &data_type, &format, output, params)?;
}
Commands::Config {
show,
create_sample,
list_rules,
} => {
cli::handle_config(show, create_sample, list_rules)?;
}
}
Ok(())
}