herdux-cli 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +390 -385
  3. package/README.pt-BR.md +390 -384
  4. package/dist/commands/backup.d.ts.map +1 -1
  5. package/dist/commands/backup.js +8 -9
  6. package/dist/commands/backup.js.map +1 -1
  7. package/dist/commands/clean.d.ts.map +1 -1
  8. package/dist/commands/clean.js +9 -10
  9. package/dist/commands/clean.js.map +1 -1
  10. package/dist/commands/config.js +2 -2
  11. package/dist/commands/config.js.map +1 -1
  12. package/dist/commands/create.d.ts.map +1 -1
  13. package/dist/commands/create.js +5 -5
  14. package/dist/commands/create.js.map +1 -1
  15. package/dist/commands/doctor.d.ts.map +1 -1
  16. package/dist/commands/doctor.js +23 -69
  17. package/dist/commands/doctor.js.map +1 -1
  18. package/dist/commands/drop.d.ts.map +1 -1
  19. package/dist/commands/drop.js +5 -5
  20. package/dist/commands/drop.js.map +1 -1
  21. package/dist/commands/list.d.ts.map +1 -1
  22. package/dist/commands/list.js +8 -6
  23. package/dist/commands/list.js.map +1 -1
  24. package/dist/commands/restore.d.ts.map +1 -1
  25. package/dist/commands/restore.js +6 -7
  26. package/dist/commands/restore.js.map +1 -1
  27. package/dist/commands/version.d.ts.map +1 -1
  28. package/dist/commands/version.js +7 -8
  29. package/dist/commands/version.js.map +1 -1
  30. package/dist/core/interfaces/database-engine.interface.d.ts +78 -0
  31. package/dist/core/interfaces/database-engine.interface.d.ts.map +1 -0
  32. package/dist/core/interfaces/database-engine.interface.js +2 -0
  33. package/dist/core/interfaces/database-engine.interface.js.map +1 -0
  34. package/dist/index.js +0 -0
  35. package/dist/infra/command-runner.d.ts.map +1 -0
  36. package/dist/infra/command-runner.js.map +1 -0
  37. package/dist/{services → infra/config}/config.service.d.ts +1 -1
  38. package/dist/infra/config/config.service.d.ts.map +1 -0
  39. package/dist/infra/config/config.service.js.map +1 -0
  40. package/dist/{services/environment.service.d.ts → infra/engines/postgres/postgres-env.d.ts} +1 -1
  41. package/dist/infra/engines/postgres/postgres-env.d.ts.map +1 -0
  42. package/dist/{services/environment.service.js → infra/engines/postgres/postgres-env.js} +5 -5
  43. package/dist/infra/engines/postgres/postgres-env.js.map +1 -0
  44. package/dist/infra/engines/postgres/postgres.engine.d.ts +17 -0
  45. package/dist/infra/engines/postgres/postgres.engine.d.ts.map +1 -0
  46. package/dist/infra/engines/postgres/postgres.engine.js +377 -0
  47. package/dist/infra/engines/postgres/postgres.engine.js.map +1 -0
  48. package/dist/infra/engines/postgres/resolve-connection.d.ts +3 -0
  49. package/dist/infra/engines/postgres/resolve-connection.d.ts.map +1 -0
  50. package/dist/{utils → infra/engines/postgres}/resolve-connection.js +10 -9
  51. package/dist/infra/engines/postgres/resolve-connection.js.map +1 -0
  52. package/dist/infra/utils/detect-binary.d.ts.map +1 -0
  53. package/dist/{utils → infra/utils}/detect-binary.js +1 -1
  54. package/dist/infra/utils/detect-binary.js.map +1 -0
  55. package/dist/presentation/logger.d.ts.map +1 -0
  56. package/dist/presentation/logger.js.map +1 -0
  57. package/package.json +69 -57
  58. package/dist/core/command-runner.d.ts.map +0 -1
  59. package/dist/core/command-runner.js.map +0 -1
  60. package/dist/core/logger.d.ts.map +0 -1
  61. package/dist/core/logger.js.map +0 -1
  62. package/dist/services/backup.service.d.ts +0 -4
  63. package/dist/services/backup.service.d.ts.map +0 -1
  64. package/dist/services/backup.service.js +0 -99
  65. package/dist/services/backup.service.js.map +0 -1
  66. package/dist/services/config.service.d.ts.map +0 -1
  67. package/dist/services/config.service.js.map +0 -1
  68. package/dist/services/environment.service.d.ts.map +0 -1
  69. package/dist/services/environment.service.js.map +0 -1
  70. package/dist/services/postgres.service.d.ts +0 -27
  71. package/dist/services/postgres.service.d.ts.map +0 -1
  72. package/dist/services/postgres.service.js +0 -180
  73. package/dist/services/postgres.service.js.map +0 -1
  74. package/dist/utils/detect-binary.d.ts.map +0 -1
  75. package/dist/utils/detect-binary.js.map +0 -1
  76. package/dist/utils/resolve-connection.d.ts +0 -3
  77. package/dist/utils/resolve-connection.d.ts.map +0 -1
  78. package/dist/utils/resolve-connection.js.map +0 -1
  79. /package/dist/{core → infra}/command-runner.d.ts +0 -0
  80. /package/dist/{core → infra}/command-runner.js +0 -0
  81. /package/dist/{services → infra/config}/config.service.js +0 -0
  82. /package/dist/{utils → infra/utils}/detect-binary.d.ts +0 -0
  83. /package/dist/{core → presentation}/logger.d.ts +0 -0
  84. /package/dist/{core → presentation}/logger.js +0 -0
package/README.md CHANGED
@@ -1,385 +1,390 @@
1
- 🇺🇸 English | 🇧🇷 [Português](./README.pt-BR.md)
2
-
3
- # Herdux — Database Workflow CLI
4
-
5
- <p align="center">
6
- <strong>Infrastructure-grade power. Developer-grade experience.</strong>
7
- </p>
8
-
9
- A fast, interactive CLI that removes friction from daily local database workflows, especially when juggling multiple instances and large datasets.
10
-
11
- ![Version](https://img.shields.io/badge/version-0.2.1-blue.svg)
12
- ![License](https://img.shields.io/badge/license-MIT-green.svg)
13
- ![Node](https://img.shields.io/badge/node-18%2B-43853d.svg)
14
- [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?style=flat&logo=github)](https://github.com/sponsors/eduardozaniboni)
15
- [![Buy Me A Coffee](https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=flat&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/eduardozaniboni)
16
-
17
- > Optimized for local and development environments. Production use is supported with explicit configuration.
18
-
19
- <!-- <p align="center">
20
- <img src=".github/herdux.gif" alt="herdux terminal gif" width="1220" />
21
- </p> -->
22
-
23
- ---
24
-
25
- ## ⚡ Quick Start
26
-
27
- ```bash
28
- npm install -g herdux-cli
29
-
30
- # You can use either 'herdux' or the shorter 'hdx' alias
31
- hdx doctor
32
- herdux list
33
- ```
34
-
35
- That's it. You're managing databases.
36
-
37
- ---
38
-
39
- ## Why Herdux?
40
-
41
- Managing local databases through raw bash scripts or binaries is repetitive, error-prone, and painful at scale.
42
-
43
- ### ❌ Without Herdux
44
-
45
- ```bash
46
- # Backup a database
47
- pg_dump -U postgres -h localhost -p 5416 -Fc -f ./backups/mydb_2026-02-23.dump mydb
48
-
49
- # Then manually drop it
50
- psql -U postgres -h localhost -p 5416 -c "DROP DATABASE mydb;"
51
-
52
- # Restore from backup
53
- pg_restore -U postgres -h localhost -p 5416 -d mydb --clean --if-exists ./backups/mydb_2026-02-23.dump
54
-
55
- # Check if tools are installed
56
- psql --version && pg_dump --version && pg_restore --version
57
- ```
58
-
59
- ### ✅ With Herdux
60
-
61
- ```bash
62
- herdux backup mydb --drop --yes # Backup + drop in one shot
63
- herdux restore ./backups/mydb.dump --db mydb # Auto-creates DB if missing & detects format
64
- herdux clean # Multi-select and batch-drop databases
65
- herdux doctor # Full system health check
66
- ```
67
-
68
- Fewer flags. Fewer mistakes. Zero terminal fatigue.
69
-
70
- ---
71
-
72
- ## 🎯 Who is Herdux for?
73
-
74
- **Herdux** was built *for developers, by developers*.
75
-
76
- It was born from the daily frustration of constantly having to restore backups to test specific states, drop corrupted databases during development, and juggle raw database binaries.
77
-
78
- It is specifically designed for developers who:
79
- - Manage local infrastructures and need to check disk sizes before seeding new databases.
80
- - Want to quickly clone, seed, and reset databases without reading `man` pages.
81
- - Need safe backup & restore workflows that don't rely on fragile bash scripts.
82
- - Prefer terminal-first tooling.
83
- - Want predictable connection resolution without hidden magic.
84
-
85
- If you manage databases locally, Herdux was created to solve your pain.
86
-
87
- ---
88
-
89
- ## 🚀 Key Features
90
-
91
- - **📋 Smart Listing** — Optimized listing strategy for massive clusters. Optional `--size` flag for disk usage analysis, sorted largest-first.
92
- - **💾 Intelligent Backup & Restore** — Supports Custom (`.dump`) and Plain (`.sql`) formats. Auto-detects the right tool for restores.
93
- - **🧹 Bulk Cleanup** — Multi-select databases, optionally backup, and batch-drop them. Reclaim disk space instantly.
94
- - **🩺 System Diagnostics** — One-command health check verifying binaries, authentication, and connectivity.
95
- - **⚙️ Persistent Profiles** — Save named server configurations. Switch between environments with `-s pg16`.
96
- - **🎯 Smart Connection Resolution** — Explicit CLI flags profiles saved defaults auto-discovery. Always predictable.
97
-
98
- ---
99
-
100
- ## 💡 Philosophy
101
-
102
- **Herdux** combines *herd* and *UX* — delivering a better developer experience when managing your local database clusters. The name reflects our focus on improving the developer experience of managing database herds.
103
-
104
- **Herdux** follows three principles:
105
-
106
- - **Safety first** — Never drops data without explicit confirmation or a verified backup.
107
- - **Explicit over implicit** — Connection resolution follows a strict, documented priority. No magic.
108
- - **Developer workflow optimization** — Every command is designed to save you from repetitive terminal work.
109
-
110
- ---
111
-
112
- ## 🔒 Safety
113
-
114
- **Herdux** handles destructive operations with care:
115
-
116
- - **Never drops a database** unless explicit confirmation is given
117
- - **Aborts the entire operation** if a safety backup fails during `herdux clean`
118
- - **Validates `pg_dump` exit codes** before considering a backup successful
119
- - **Requires `--drop` flag** intentionally dropping is never the default
120
- - **`--yes` must be combined with `--drop`** cannot skip confirmation alone
121
-
122
- > If you request a backup before dropping and that backup fails, **Herdux** stops immediately. No data is lost.
123
-
124
-
125
- ---
126
-
127
- ## 🧩 Requirements
128
-
129
- - **Node.js** 18 or higher
130
- - **PostgreSQL client tools** (`psql`, `pg_dump`, `pg_restore`) installed and available in your `PATH`
131
-
132
- > [!TIP]
133
- > Run `herdux doctor` after installation to verify everything is set up correctly.
134
-
135
- ---
136
-
137
- ## 📦 Installation
138
-
139
- **npm (recommended):**
140
-
141
- > **⚠️ IMPORTANT:** You must use the `-g` (global) flag for the CLI to be accessible anywhere in your terminal.
142
-
143
- ```bash
144
- npm install -g herdux-cli
145
- ```
146
-
147
- **From source:**
148
-
149
- ```bash
150
- git clone https://github.com/eduardozaniboni/herdux.git
151
- cd herdux
152
- npm install
153
- npm run build
154
- npm link
155
- ```
156
-
157
- ---
158
-
159
- ## 🛠️ Commands
160
-
161
- ### `herdux version`
162
-
163
- Shows the CLI version and the connected PostgreSQL server version.
164
-
165
- ```bash
166
- herdux version
167
- ```
168
-
169
- ### `herdux doctor`
170
-
171
- Runs a full system health check:
172
-
173
- - Verifies `psql`, `pg_dump`, and `pg_restore` are installed and reachable
174
- - Attempts a live connection using the resolved configuration
175
- - Tests authentication against the target server
176
-
177
- ```bash
178
- herdux doctor
179
- ```
180
-
181
- ---
182
-
183
- ### 📋 `herdux list`
184
-
185
- Lists all databases on the connected server.
186
-
187
- ```bash
188
- herdux list # Fast listing (name, owner, encoding)
189
- herdux ls --size # Includes disk size, sorted largest → smallest
190
- ```
191
-
192
- > [!NOTE]
193
- > The `--size` flag calculates physical disk usage via `pg_database_size()`. On servers with dozens of multi-GB databases, this may take a few minutes depending on disk speed.
194
-
195
- ---
196
-
197
- ### `herdux create <name>`
198
-
199
- Creates a new database.
200
-
201
- ```bash
202
- herdux create my_new_db
203
- ```
204
-
205
- ### `herdux drop <name>`
206
-
207
- Drops a database with interactive confirmation.
208
-
209
- ```bash
210
- herdux drop my_old_db
211
- ```
212
-
213
- ---
214
-
215
- ### 🧹 `herdux clean` — Bulk Cleanup
216
-
217
- Working with seed-heavy development databases? Need to reclaim disk space fast?
218
-
219
- `herdux clean` allows you to:
220
-
221
- - **Multi-select** databases from an interactive checkbox UI
222
- - **Optionally generate safety backups** before any destructive action
223
- - **Batch-drop** all selected databases safely
224
- - **Abort immediately** if any backup fails, preventing data loss
225
-
226
- ```bash
227
- herdux clean
228
- ```
229
-
230
- This is designed for the real-world dev workflow: clone databases, experiment, then clean up everything in one shot.
231
-
232
- ---
233
-
234
- ### 📦 `herdux backup <database>`
235
-
236
- Generates a timestamped backup in `./backups/`.
237
-
238
- ```bash
239
- herdux backup mydb # Custom format (.dump)
240
- herdux backup mydb --format plain # Plain SQL (.sql)
241
- herdux backup mydb --drop # Backup, then ask to drop
242
- herdux backup mydb --drop --yes # Backup + drop, no questions
243
- herdux backup mydb -o ./my-backups # Custom output directory
244
- ```
245
-
246
- | Option | Description |
247
- |---|---|
248
- | `-F, --format <type>` | `custom` (default, compressed) or `plain` (raw SQL) |
249
- | `-d, --drop` | Prompt to drop database after successful backup |
250
- | `-y, --yes` | Skip drop confirmation (requires `--drop`) |
251
- | `-o, --output <dir>` | Output directory (default: `./backups`) |
252
-
253
- ---
254
-
255
- ### 📥 `herdux restore <file>`
256
-
257
- Restores a database from a backup file. Automatically detects the format:
258
-
259
- - `.sql` → uses `psql -f`
260
- - `.dump` or any other extension → uses `pg_restore`
261
-
262
- ```bash
263
- herdux restore ./backups/mydb_2026-02-23.dump --db mydb
264
- herdux restore ./exports/data.sql --db mydb
265
- ```
266
-
267
- Need to override auto-detection? Use `--format`:
268
-
269
- ```bash
270
- herdux restore archive.bkp --db mydb --format custom
271
- herdux restore script.txt --db mydb --format plain
272
- ```
273
-
274
- ---
275
-
276
- ## ⚙️ Configuration & Server Profiles
277
-
278
- `herdux` stores configuration locally at `~/.herdux/config.json`.
279
-
280
- ### Set Global Defaults
281
-
282
- ```bash
283
- herdux config set user postgres
284
- herdux config set password my_secret
285
- herdux config set port 5432
286
- ```
287
-
288
- ### Named Server Profiles
289
-
290
- Manage multiple database instances effortlessly:
291
-
292
- ```bash
293
- herdux config add pg16 --port 5416
294
- herdux config add pg17 --port 5417 --user admin
295
- herdux config add staging --host 192.168.0.10 --port 5432
296
- ```
297
-
298
- Then connect using the `-s` flag:
299
-
300
- ```bash
301
- herdux list -s pg16
302
- herdux backup mydb -s staging
303
- ```
304
-
305
- ### View & Manage Config
306
-
307
- ```bash
308
- herdux config list # Show all saved settings and profiles
309
- herdux config get port # Get a specific value
310
- herdux config rm pg16 # Remove a server profile
311
- herdux config reset # Clear all configuration
312
- ```
313
-
314
- ---
315
-
316
- ## 🔌 Connection Priority
317
-
318
- When resolving how to connect, **Herdux** follows a strict, predictable priority order:
319
-
320
- | Priority | Source | Example |
321
- |---|---|---|
322
- | 1️⃣ | **CLI flags** | `herdux list --port 5417` |
323
- | 2️⃣ | **Server profile** | `herdux list -s pg16` |
324
- | 3️⃣ | **Saved defaults** | `herdux config set port 5432` |
325
- | 4️⃣ | **Auto-discovery** | Scans common ports; prompts if multiple found |
326
-
327
- This means explicit input always wins. No surprises.
328
-
329
- ---
330
-
331
- ## 🤔 Why not pgAdmin?
332
-
333
- **Herdux** is not a GUI replacement.
334
- It’s a workflow accelerator for developers who live in the terminal.
335
-
336
- No GUI. No overhead. Just speed.
337
-
338
- ---
339
-
340
- ## 🧠 Design Principles
341
-
342
- - No hidden defaults.
343
- - No destructive magic.
344
- - Deterministic connection resolution.
345
- - Explicit and composable commands.
346
-
347
- ---
348
-
349
- ## 🐳 Docker Support (Coming Soon)
350
-
351
- **Herdux** will be able to detect and interact with PostgreSQL instances running inside Docker containers — listing, connecting, and managing them as naturally as local instances.
352
-
353
- ---
354
-
355
- ## 🗺 Roadmap
356
-
357
- See [ROADMAP.md](./ROADMAP.md) for our detailed future plans, including Docker integration and encrypted backups.
358
-
359
- ---
360
-
361
- ## 🤝 Contributing
362
-
363
- PRs are welcome! Please open an issue first to discuss major changes.
364
-
365
- ```bash
366
- git clone https://github.com/eduardozaniboni/herdux.git
367
- cd herdux
368
- npm install
369
- npm run dev
370
- ```
371
-
372
- ---
373
-
374
- ## Support the Project
375
-
376
- If **Herdux** has saved you hours of debugging and database wrangling, consider supporting the project! It helps keep it active and open-source.
377
-
378
- <a href="https://github.com/sponsors/eduardozaniboni" target="_blank"><img src="https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?style=for-the-badge&logo=github" alt="GitHub Sponsors"></a>
379
- <a href="https://www.buymeacoffee.com/eduardozaniboni" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 28px !important;width: 100px !important;" ></a>
380
-
381
- ---
382
-
383
- ## 📄 License
384
-
385
- MIT
1
+ 🇺🇸 English | 🇧🇷 [Português](./README.pt-BR.md)
2
+
3
+ # Herdux — Database Workflow CLI
4
+
5
+ <p align="center">
6
+ <strong>Infrastructure-grade power. Developer-grade experience.</strong>
7
+ </p>
8
+
9
+ A fast, interactive CLI that removes friction from daily local database workflows, especially when juggling multiple instances and large datasets.
10
+
11
+ ![Version](https://img.shields.io/badge/version-0.3.0-blue.svg)
12
+ ![License](https://img.shields.io/badge/license-MIT-green.svg)
13
+ ![Node](https://img.shields.io/badge/node-18%2B-43853d.svg)
14
+ [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?style=flat&logo=github)](https://github.com/sponsors/eduardozaniboni)
15
+ [![Buy Me A Coffee](https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=flat&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/eduardozaniboni)
16
+
17
+ > Optimized for local and development environments. Production use is supported with explicit configuration.
18
+
19
+ <!-- <p align="center">
20
+ <img src=".github/herdux.gif" alt="herdux terminal gif" width="1220" />
21
+ </p> -->
22
+
23
+ ---
24
+
25
+ ## ⚡ Quick Start
26
+
27
+ ```bash
28
+ npm install -g herdux-cli
29
+
30
+ # You can use either 'herdux' or the shorter 'hdx' alias
31
+ hdx doctor
32
+ herdux list
33
+ ```
34
+
35
+ That's it. You're managing databases.
36
+
37
+ ---
38
+
39
+ ## Why Herdux?
40
+
41
+ Managing local databases through raw bash scripts or binaries is repetitive, error-prone, and painful at scale.
42
+
43
+ ### ❌ Without Herdux
44
+
45
+ ```bash
46
+ # Backup a database
47
+ pg_dump -U postgres -h localhost -p 5416 -Fc -f ./backups/mydb_2026-02-23.dump mydb
48
+
49
+ # Then manually drop it
50
+ psql -U postgres -h localhost -p 5416 -c "DROP DATABASE mydb;"
51
+
52
+ # Restore from backup
53
+ pg_restore -U postgres -h localhost -p 5416 -d mydb --clean --if-exists ./backups/mydb_2026-02-23.dump
54
+
55
+ # Check if tools are installed
56
+ psql --version && pg_dump --version && pg_restore --version
57
+ ```
58
+
59
+ ### ✅ With Herdux
60
+
61
+ ```bash
62
+ herdux backup mydb --drop --yes # Backup + drop in one shot
63
+ herdux restore ./backups/mydb.dump --db mydb # Auto-creates DB if missing & detects format
64
+ herdux clean # Multi-select and batch-drop databases
65
+ herdux doctor # Full system health check
66
+ ```
67
+
68
+ Fewer flags. Fewer mistakes. Zero terminal fatigue.
69
+
70
+ ---
71
+
72
+ ## 🎯 Who is Herdux for?
73
+
74
+ **Herdux** was built _for developers, by developers_.
75
+
76
+ It was born from the daily frustration of constantly having to restore backups to test specific states, drop corrupted databases during development, and juggle raw database binaries.
77
+
78
+ It is specifically designed for developers who:
79
+
80
+ - Manage local infrastructures and need to check disk sizes before seeding new databases.
81
+ - Want to quickly clone, seed, and reset databases without reading `man` pages.
82
+ - Need safe backup & restore workflows that don't rely on fragile bash scripts.
83
+ - Prefer terminal-first tooling.
84
+ - Want predictable connection resolution without hidden magic.
85
+
86
+ If you manage databases locally, Herdux was created to solve your pain.
87
+
88
+ ---
89
+
90
+ ## 🚀 Key Features
91
+
92
+ - **📋 Smart Listing** — Optimized listing strategy for massive clusters. Optional `--size` flag for disk usage analysis, sorted largest-first.
93
+ - **💾 Intelligent Backup & Restore** — Supports Custom (`.dump`) and Plain (`.sql`) formats. Auto-detects the right tool for restores.
94
+ - **🧹 Bulk Cleanup** — Multi-select databases, optionally backup, and batch-drop them. Reclaim disk space instantly.
95
+ - **🩺 System Diagnostics** — One-command health check verifying binaries, authentication, and connectivity.
96
+ - **⚙️ Persistent Profiles** — Save named server configurations. Switch between environments with `-s pg16`.
97
+ - **🎯 Smart Connection Resolution** — Explicit CLI flags → profiles → saved defaults → auto-discovery. Always predictable.
98
+
99
+ ---
100
+
101
+ ## 💡 Philosophy
102
+
103
+ **Herdux** combines _herd_ and _UX_ — delivering a better developer experience when managing your local database clusters. The name reflects our focus on improving the developer experience of managing database herds.
104
+
105
+ **Herdux** follows three principles:
106
+
107
+ - **Safety first** — Never drops data without explicit confirmation or a verified backup.
108
+ - **Explicit over implicit** — Connection resolution follows a strict, documented priority. No magic.
109
+ - **Developer workflow optimization** — Every command is designed to save you from repetitive terminal work.
110
+
111
+ ---
112
+
113
+ ## 🔒 Safety
114
+
115
+ **Herdux** handles destructive operations with care:
116
+
117
+ - **Never drops a database** unless explicit confirmation is given
118
+ - **Aborts the entire operation** if a safety backup fails during `herdux clean`
119
+ - **Validates `pg_dump` exit codes** before considering a backup successful
120
+ - **Requires `--drop` flag** intentionally dropping is never the default
121
+ - **`--yes` must be combined with `--drop`** — cannot skip confirmation alone
122
+
123
+ > If you request a backup before dropping and that backup fails, **Herdux** stops immediately. No data is lost.
124
+
125
+ ---
126
+
127
+ ## 🧩 Requirements
128
+
129
+ - **Node.js** 18 or higher
130
+ - **PostgreSQL client tools** (`psql`, `pg_dump`, `pg_restore`) installed and available in your `PATH`
131
+
132
+ > [!TIP]
133
+ > Run `herdux doctor` after installation to verify everything is set up correctly.
134
+
135
+ ---
136
+
137
+ ## 📦 Installation
138
+
139
+ **npm (recommended):**
140
+
141
+ > **⚠️ IMPORTANT:** You must use the `-g` (global) flag for the CLI to be accessible anywhere in your terminal.
142
+
143
+ ```bash
144
+ npm install -g herdux-cli
145
+ ```
146
+
147
+ **From source:**
148
+
149
+ ```bash
150
+ git clone https://github.com/herdux/herdux-cli.git
151
+ cd herdux-cli
152
+ npm install
153
+ npm run build
154
+ npm link
155
+ ```
156
+
157
+ ---
158
+
159
+ ## 🛠️ Commands
160
+
161
+ ### `herdux version`
162
+
163
+ Shows the CLI version and the connected PostgreSQL server version.
164
+
165
+ ```bash
166
+ herdux version
167
+ ```
168
+
169
+ ### `herdux doctor`
170
+
171
+ Runs a full system health check:
172
+
173
+ - Verifies `psql`, `pg_dump`, and `pg_restore` are installed and reachable
174
+ - Attempts a live connection using the resolved configuration
175
+ - Tests authentication against the target server
176
+
177
+ ```bash
178
+ herdux doctor
179
+ ```
180
+
181
+ ---
182
+
183
+ ### 📋 `herdux list`
184
+
185
+ Lists all databases on the connected server.
186
+
187
+ ```bash
188
+ herdux list # Fast listing (name, owner, encoding)
189
+ herdux ls --size # Includes disk size, sorted largest → smallest
190
+ ```
191
+
192
+ > [!NOTE]
193
+ > The `--size` flag calculates physical disk usage via `pg_database_size()`. On servers with dozens of multi-GB databases, this may take a few minutes depending on disk speed.
194
+
195
+ ---
196
+
197
+ ### `herdux create <name>`
198
+
199
+ Creates a new database.
200
+
201
+ ```bash
202
+ herdux create my_new_db
203
+ ```
204
+
205
+ ### `herdux drop <name>`
206
+
207
+ Drops a database with interactive confirmation.
208
+
209
+ ```bash
210
+ herdux drop my_old_db
211
+ ```
212
+
213
+ ---
214
+
215
+ ### 🧹 `herdux clean` — Bulk Cleanup
216
+
217
+ Working with seed-heavy development databases? Need to reclaim disk space fast?
218
+
219
+ `herdux clean` allows you to:
220
+
221
+ - **Multi-select** databases from an interactive checkbox UI
222
+ - **Optionally generate safety backups** before any destructive action
223
+ - **Batch-drop** all selected databases safely
224
+ - **Abort immediately** if any backup fails, preventing data loss
225
+
226
+ ```bash
227
+ herdux clean
228
+ ```
229
+
230
+ This is designed for the real-world dev workflow: clone databases, experiment, then clean up everything in one shot.
231
+
232
+ ---
233
+
234
+ ### 📦 `herdux backup <database>`
235
+
236
+ Generates a timestamped backup in `./backups/`.
237
+
238
+ ```bash
239
+ herdux backup mydb # Custom format (.dump)
240
+ herdux backup mydb --format plain # Plain SQL (.sql)
241
+ herdux backup mydb --drop # Backup, then ask to drop
242
+ herdux backup mydb --drop --yes # Backup + drop, no questions
243
+ herdux backup mydb -o ./my-backups # Custom output directory
244
+ ```
245
+
246
+ | Option | Description |
247
+ | --------------------- | --------------------------------------------------- |
248
+ | `-F, --format <type>` | `custom` (default, compressed) or `plain` (raw SQL) |
249
+ | `-d, --drop` | Prompt to drop database after successful backup |
250
+ | `-y, --yes` | Skip drop confirmation (requires `--drop`) |
251
+ | `-o, --output <dir>` | Output directory (default: `./backups`) |
252
+
253
+ ---
254
+
255
+ ### 📥 `herdux restore <file>`
256
+
257
+ Restores a database from a backup file. Automatically detects the format:
258
+
259
+ - `.sql` → uses `psql -f`
260
+ - `.dump` or any other extension → uses `pg_restore`
261
+
262
+ ```bash
263
+ herdux restore ./backups/mydb_2026-02-23.dump --db mydb
264
+ herdux restore ./exports/data.sql --db mydb
265
+ ```
266
+
267
+ Need to override auto-detection? Use `--format`:
268
+
269
+ ```bash
270
+ herdux restore archive.bkp --db mydb --format custom
271
+ herdux restore script.txt --db mydb --format plain
272
+ ```
273
+
274
+ ---
275
+
276
+ ## ⚙️ Configuration & Server Profiles
277
+
278
+ `herdux` stores configuration locally at `~/.herdux/config.json`.
279
+
280
+ ### Set Global Defaults
281
+
282
+ ```bash
283
+ herdux config set user postgres
284
+ herdux config set password my_secret
285
+ herdux config set port 5432
286
+ ```
287
+
288
+ ### Named Server Profiles
289
+
290
+ Manage multiple database instances effortlessly:
291
+
292
+ ```bash
293
+ herdux config add pg16 --port 5416
294
+ herdux config add pg17 --port 5417 --user admin
295
+ herdux config add staging --host 192.168.0.10 --port 5432
296
+ ```
297
+
298
+ Then connect using the `-s` flag:
299
+
300
+ ```bash
301
+ herdux list -s pg16
302
+ herdux backup mydb -s staging
303
+ ```
304
+
305
+ ### View & Manage Config
306
+
307
+ ```bash
308
+ herdux config list # Show all saved settings and profiles
309
+ herdux config get port # Get a specific value
310
+ herdux config rm pg16 # Remove a server profile
311
+ herdux config reset # Clear all configuration
312
+ ```
313
+
314
+ ---
315
+
316
+ ## 🔌 Connection Priority
317
+
318
+ When resolving how to connect, **Herdux** follows a strict, predictable priority order:
319
+
320
+ | Priority | Source | Example |
321
+ | -------- | ------------------ | --------------------------------------------- |
322
+ | 1️⃣ | **CLI flags** | `herdux list --port 5417` |
323
+ | 2️⃣ | **Server profile** | `herdux list -s pg16` |
324
+ | 3️⃣ | **Saved defaults** | `herdux config set port 5432` |
325
+ | 4️⃣ | **Auto-discovery** | Scans common ports; prompts if multiple found |
326
+
327
+ This means explicit input always wins. No surprises.
328
+
329
+ ---
330
+
331
+ ## 🤔 Why not pgAdmin?
332
+
333
+ **Herdux** is not a GUI replacement.
334
+ It’s a workflow accelerator for developers who live in the terminal.
335
+
336
+ No GUI. No overhead. Just speed.
337
+
338
+ ---
339
+
340
+ ## 🧠 Design Principles
341
+
342
+ - No hidden defaults.
343
+ - No destructive magic.
344
+ - Deterministic connection resolution.
345
+ - Explicit and composable commands.
346
+
347
+ ---
348
+
349
+ ## 🐳 Docker Support (Coming Soon)
350
+
351
+ **Herdux** will be able to detect and interact with PostgreSQL instances running inside Docker containers — listing, connecting, and managing them as naturally as local instances.
352
+
353
+ ---
354
+
355
+ ## 🗺 Roadmap
356
+
357
+ See [ROADMAP.md](./ROADMAP.md) for our detailed future plans, including Docker integration and encrypted backups.
358
+
359
+ ---
360
+
361
+ ## 🤝 Contributing
362
+
363
+ PRs are welcome! Please open an issue first to discuss major changes.
364
+
365
+ ```bash
366
+ git clone https://github.com/herdux/herdux-cli.git
367
+ cd herdux-cli
368
+ npm install
369
+ npm run dev
370
+
371
+ # Run the unit test suite
372
+ npm run test:unit
373
+ # Run the test suite (requires Docker for E2E)
374
+ npm run test:e2e
375
+ ```
376
+
377
+ ---
378
+
379
+ ## Support the Project
380
+
381
+ If **Herdux** has saved you hours of debugging and database wrangling, consider supporting the project! It helps keep it active and open-source.
382
+
383
+ <a href="https://github.com/sponsors/eduardozaniboni" target="_blank"><img src="https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?style=for-the-badge&logo=github" alt="GitHub Sponsors"></a>
384
+ <a href="https://www.buymeacoffee.com/eduardozaniboni" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 28px !important;width: 100px !important;" ></a>
385
+
386
+ ---
387
+
388
+ ## 📄 License
389
+
390
+ MIT