librius 0.4.1

A personal library manager CLI written in Rust.
Documentation
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<h1 style="text-align: left;">
  <img src="res/librius.svg" width="90" style="vertical-align: middle; margin-right: 8px;" alt="Librius Logo"/>
  Librius
</h1>

[![Build Status](https://github.com/umpire274/librius/actions/workflows/ci.yml/badge.svg)](https://github.com/umpire274/librius/actions)
[![Docs.rs](https://docs.rs/librius/badge.svg)](https://docs.rs/librius)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Rust Edition](https://img.shields.io/badge/Rust-2024-orange.svg)](https://www.rust-lang.org/)

> **Librius** โ€” A fast, minimalist CLI to manage your personal book collection, built in Rust.

---

## ๐Ÿงพ Overview

**Librius** is a cross-platform **command-line tool** written in Rust that helps you manage your personal library.  
It uses a **SQLite** database to store your books and a simple **YAML** configuration file
(`librius.conf`) for flexible setup.

This project aims to provide a clean, modular architecture with future extensions such as search, add/remove commands,
and import/export support.

---

## โœจ New in v0.4.1

**๐Ÿ—‘๏ธ Book deletion command**

- Introduced the new `del <ID|ISBN>` command for removing books from your library.
- Supports both numeric IDs and ISBN codes with automatic detection.
- Added **interactive confirmation** to prevent accidental deletions.
- Added `--force` flag for non-interactive or scripted deletions.
- All deletions are now recorded via `write_log()` for full audit traceability.

**๐ŸŒ Localization & Help**

- Localized all new messages, confirmations, and help strings in **English** and **Italian**.
- Updated CLI help sections to include the new command and `--force` option.

**๐Ÿงฐ Developer improvements**

- Added developer scripts in `/tools` for build and submodule verification.
- Updated private submodule `tools_private` to the latest revision.

---

## ๐Ÿ“ฆ Installation

### ๐Ÿง AUR (Arch Linux)

[![AUR](https://img.shields.io/aur/version/librius)](https://aur.archlinux.org/packages/librius)

```bash
yay -S librius
# or
paru -S librius
```

### ๐Ÿบ Homebrew (macOS/Linux)

[![Homebrew Version](https://img.shields.io/github/v/release/umpire274/librius?label=Homebrew&logo=homebrew&color=brightgreen)](https://github.com/umpire274/homebrew-tap)

```bash
brew tap umpire274/tap
brew install librius
```

### ๐Ÿฆ€ Crates.io (Rust)

[![Crates.io](https://img.shields.io/crates/v/librius)](https://crates.io/crates/librius)

```bash
cargo install rtimelogger
```

---

## โš™๏ธ Features

| Feature                  | Command                          | Description                                                                                                   |
|:-------------------------|:---------------------------------|:--------------------------------------------------------------------------------------------------------------|
| **List**                 | `librius list`                   | Display all books stored in the local database, in full or compact view                                       |
| **Config management**    | `librius config`                 | Manage YAML configuration via `--print`, `--init`, `--edit`, `--editor`                                       |
| **Backup**               | `librius backup`                 | Create plain or compressed database backups (`.sqlite`, `.zip`, `.tar.gz`)                                    |
| **Export**               | `librius export`                 | Export data in CSV, JSON, or XLSX format                                                                      |
| **Import**               | `librius import`                 | Import data from CSV or JSON files (duplicate-safe via ISBN)                                                  |
| **Database migrations**  | *(automatic)*                    | Automatic schema upgrades and integrity checks at startup                                                     |
| **Logging system**       | *(internal)*                     | Records all operations and migrations in an internal log table                                                |
| **Multilanguage (i18n)** | `librius --lang <code>`          | Fully localized CLI (commands, help, messages); `--lang` flag and config key                                  |
| **Add book**             | `librius add book --isbn <ISBN>` | Add new books using ISBN lookup via Google Books API                                                          |
| **Edit book**            | `librius edit book <ID/ISBN>`    | Edit existing records by ID or ISBN; dynamic field generation, language conversion, and plural-aware messages |
| **Delete book**          | `del <ID/ISBN>`                  | Delete books by ID or ISBN, with interactive confirmation, `--force` flag, and logged deletions               |
| **Dynamic help system**  | `librius help <command>`         | Ordered and grouped help output using `display_order()` and `next_help_heading()`                             |

---

## ๐Ÿ’ป Usage

```bash
librius list          # Full detailed list
librius list --short  # Compact list (ID, Title, Author, Editor, Year)
``` 

---

## ๐Ÿงฑ Example output

```bash
$ librius list --short

๐Ÿ“š  Personal Library
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ID โ”‚ Title                        โ”‚ Author             โ”‚ Editor       โ”‚ Year โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ The Rust Programming Languageโ”‚ Steve Klabnik      โ”‚ No Starch    โ”‚ 2018 โ”‚
โ”‚ 2  โ”‚ Clean Code                   โ”‚ Robert C. Martin   โ”‚ Pearson      โ”‚ 2008 โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”˜


# โž• Add a book automatically by ISBN
$ librius add book --isbn 9788820382698
๐Ÿ“˜ Book โ€œLa lingua dell'antico Egittoโ€ successfully added.

# โœ๏ธ Edit book details
$ librius edit book 9788820382698 --year 2020
โœ… Field โ€œyearโ€ updated successfully (2018 โ†’ 2020).
โœ… Book 9788820382698 successfully updated (1 field modified).

# ๐ŸŒ Update language (auto conversion from ISO)
$ librius edit book 9788820382698 --lang_book en
โœ… Field โ€œlanguageโ€ updated successfully (Italian โ†’ English).

# ๐Ÿ“š List your library (compact view)
$ librius list --short

$ librius del 128
Sei sicuro di voler eliminare il libro 128? [y/N]: y
โœ… Libro 128 eliminato correttamente.

$ librius del 9788820382698 --force
โœ… Book 9788820382698 deleted successfully.


```

---

## ๐ŸŒ Multilanguage support (i18n)

Librius now supports a multilingual interface.

| Source       | 	Description                                                    |
|--------------|-----------------------------------------------------------------|
| ๐Ÿ‡ฌ๐Ÿ‡ง en.json | 	Default English messages                                       |
| ๐Ÿ‡ฎ๐Ÿ‡น it.json | 	Italian translation                                            |
| ๐Ÿ“„ README.md | 	Located in src/i18n/locales/, describes key naming conventions |

### How it works

- On startup, Librius loads the language defined in:
    1. CLI argument --lang / -l
    2. Configuration file language:
    3. Fallback to English (en)
- All user-visible messages (print_info, print_err, etc.) are translated dynamically.
- Missing keys automatically fall back to their key name or English equivalent.

### Example Usage

```bash
# Default (English)
librius list

# Force Italian interface
librius --lang it list
```

### Example config (`librius.conf`)

```yaml
# librius.conf
database: "C:/Users/YourName/AppData/Roaming/librius/librius.sqlite"
language: "it"  # Set default language to Italian
```

---

## ๐Ÿงฉ Translations

All translations are stored in:

```bash
src/i18n/locales/
โ”œโ”€โ”€ en.json
โ”œโ”€โ”€ it.json
โ””โ”€โ”€ README.md
```

Each `.json` file contains keyโ€“value pairs like:

```json
{
  "app.config.loading": "Loading configuration...",
  "db.init.ok": "Database created successfully.",
  "book.add.ok": "Book '{title}' added successfully!"
}
```

Variables can be inserted at runtime:

```rust
tr_with("db.path.open_existing", & [("path", & db_path)]);
```

---

## ๐Ÿงฑ Project structure

```
src/
โ”œโ”€ main.rs
โ”œโ”€ lib.rs
โ”œโ”€ cli.rs
โ”‚
โ”œโ”€ commands/
โ”‚   โ”œโ”€ mod.rs
โ”‚   โ”œโ”€ list.rs
โ”‚   โ”œโ”€ backup.rs
โ”‚   โ”œโ”€ config.rs
โ”‚   โ”œโ”€ export.rs
โ”‚   โ””โ”€ import.rs
โ”‚
โ”œโ”€ config/
โ”‚   โ”œโ”€ mod.rs
โ”‚   โ”œโ”€ load_config.rs
โ”‚   โ””โ”€ migrate_config.rs
โ”‚
โ”œโ”€ db/
โ”‚   โ”œโ”€ mod.rs
โ”‚   โ”œโ”€ load_db.rs
โ”‚   โ””โ”€ migrate_db.rs
โ”‚
โ”œโ”€ i18n/
โ”‚   โ”œโ”€ mod.rs
โ”‚   โ”œโ”€ loader.rs
โ”‚   โ””โ”€ locales/
โ”‚       โ”œโ”€ en.json
โ”‚       โ”œโ”€ it.json
โ”‚       โ””โ”€ README.md
โ”‚
โ”œโ”€ models/
โ”‚   โ”œโ”€ mod.rs
โ”‚   โ””โ”€ book.rs
โ”‚
โ””โ”€ utils/
    โ”œโ”€ mod.rs
    โ””โ”€ table.rs
```

---

## ๐Ÿงพ Changelog reference

See [CHANGELOG.md](CHANGELOG.md) for a detailed list of changes and updates.

---

## ๐Ÿ“ค Export & ๐Ÿ“ฅ Import

Librius now supports full data import/export functionality.

### Export

You can export your library to multiple formats:

```bash
librius export --csv     # CSV (default)
librius export --json    # JSON
librius export --xlsx    # Excel (XLSX)
```

Exports are automatically saved in your user data directory
(e.g. `~/.config/librius/exports` or `%APPDATA%\librius\exports`).

### Import

Import books from CSV or JSON files:

```bash
librius import --file examples/books.csv
librius import --file examples/books.json --json
```

Features:

- Automatic detection of duplicate records via unique `isbn`
- Skips duplicates gracefully (no interruption)
- Transaction-safe import
- Verbose mode logs skipped ISBNs

Example output:

```bash
๐Ÿ“˜  Skipped duplicate ISBN: 978-0-345-33968-3
โœ… Imported 6 records from CSV file.
```

---

## ๐Ÿš€ Quick start

### 1๏ธโƒฃ Clone the repository

```bash
git clone https://github.com/umpire274/librius.git
cd librius
```

### 2๏ธโƒฃ Build and run

```bash
cargo build
cargo run -- list
```

If this is the first launch, Librius will automatically create:

- The config file at `~/.config/librius/librius.conf`
- A SQLite database at `~/.config/librius/librius.sqlite`

---

## ๐Ÿงฉ Example output

$ librius list

๐Ÿ“š Your Library

1. The Hobbit (J.R.R. Tolkien) [1937]
2. Foundation (Isaac Asimov) [1951]
3. Dune (Frank Herbert) [1965]

---

## โš™๏ธ Configuration

```yaml
# librius.conf
database: "C:/Users/YourName/AppData/Roaming/librius/librius.sqlite"
language: "en"
```

- Configuration file is automatically migrated if fields are missing or renamed.
- Default path:
    - macOS/Linux โ†’ $HOME/.librius/librius.conf
    - Windows โ†’ %APPDATA%\Roaming\librius\librius.conf

---

## ๐Ÿงฉ Development notes

Librius now follows a standard Rust modular structure:

- Each domain (commands, db, config, models, utils, i18n) exposes its API via mod.rs.
- Common utilities like build_table() are reused across commands for consistent output.
- The lib.rs re-exports all major modules for cleaner imports in main.rs.

### Example import

```rust
use librius::{build_cli, handle_list; tr};
```

---

## ๐Ÿ“š Documentation

The API and user-facing documentation for Librius is available on docs.rs:

- Online: https://docs.rs/librius

To generate and view the documentation locally run:

```bash
cargo doc --no-deps --open
```

This will build the documentation and open it in your default browser.

---

## ๐Ÿงฐ Dependencies

- **clap** โ€” Command-line argument parsing
- **rusqlite** โ€” SQLite database integration
- **serde / serde_json** โ€” Serialization/deserialization
- **serde_yaml** โ€” YAML config parsing
- **umya-spreadsheet** โ€” XLSX file creation
- **csv** โ€” CSV import/export
- **colored** โ€” Colored terminal output
- **chrono** โ€” Date and time utilities

---

## ๐Ÿ—„๏ธ Database management

Librius automatically verifies and upgrades the SQLite database schema at startup.

The latest migration adds a unique index on `isbn` to guarantee
that duplicate imports are ignored safely.

```sql
CREATE UNIQUE INDEX IF NOT EXISTS idx_books_isbn ON books(isbn);
```

- On first launch โ†’ creates books table.
- On subsequent launches โ†’ runs pending migrations silently.
- Migration results are recorded in the log table.

Each migration patch (`PATCH_001`, `PATCH_002`, โ€ฆ) is applied once and recorded in the internal log table.
The process is fully idempotent โ€” no duplicate operations are ever performed.

```pgsql
๐Ÿ“˜  Applying database patch: PATCH_002
โœ…  All pending migrations applied.
โœ…  Database schema is up-to-date.
```

### Example table `log`

| id | date                      | operation       | target | message                     |
|----|---------------------------|-----------------|--------|-----------------------------|
| 1  | 2025-10-13T21:45:12+02:00 | DB_CREATED      | DB     | Created new database        |
| 2  | 2025-10-13T21:45:13+02:00 | DB_MIGRATION_OK | DB     | Schema updated successfully |

---

๐Ÿ” Verbose mode

Run Librius in diagnostic mode to display all internal initialization steps:

```bash
librius --verbose list
```

Output example:

```bash
๐Ÿ“˜  Loading configuration...
๐Ÿ“˜  Opening existing database at: C:\Users\A.Maestri\AppData\Roaming\librius\librius.db
โœ… Database schema is up-to-date.
โœ… Configuration verified.

๐Ÿ“š Your Library
```

In normal mode, only command output is displayed.

---

## ๐Ÿงช Development

### Run in debug mode

```bash
cargo run -- list
```

### Run with logging (future)

```bash
RUST_LOG=debug cargo run -- add "Neuromancer"
```

### Format and lint

```bash
cargo fmt
cargo clippy
```

---

## ๐Ÿงฑ Future roadmap

- Add `add`, `remove`, and `search` commands
- Export/import JSON and CSV
- Add optional TUI (Text UI) with `ratatui`
- Web dashboard sync

---

## ๐Ÿง‘โ€๐Ÿ’ป Author

Umpire274
GitHub: [@umpire274](https://github.com/umpire274)

---

## ๐Ÿ“œ License

This project is licensed under the MIT License โ€” see the LICENSE

---

## โญ Contribute

Contributions, feature requests, and ideas are welcome!
If youโ€™d like to contribute, please open a pull request or start a discussion.

---

## ๐Ÿงก Support

If you enjoy this project, please โญ star the repository โ€” it helps visibility and development motivation!

---