Skip to content

Commit 6a3c4fd

Browse files
docs: update CLI usage
1 parent 0bbf5d5 commit 6a3c4fd

1 file changed

Lines changed: 255 additions & 2 deletions

File tree

docs/usage/cli.md

Lines changed: 255 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
date: 2025-10-17 10:58:59
2+
date: 2025-11-05 20:30:00
33
title: Command Line Interface
44
permalink:
5-
publish: false
5+
publish: true
66
---
77

88
# Command Line Interface
@@ -13,3 +13,256 @@ You can use the command line interface to manage your documentations and their a
1313

1414
## Overview
1515

16+
Since `v3`, the CLI has been rewritten to be greatly simplified.
17+
18+
In `v3.0.x`, there only has commands to create, remove, move notes with there correspondingly assets directories and clean up orphaned asset directories:
19+
20+
| Commands | Description |
21+
|:----------:|:-------------:|
22+
| `new` | Create a new note file with proper asset structure. |
23+
| `remove` | Remove a note file and its corresponding asset directory. |
24+
| `move` | Move a note file and its corresponding asset directory to a new location. |
25+
| `clean` | Clean up orphaned asset directories. |
26+
27+
## Commands Detail
28+
29+
### `new`
30+
31+
Create a new note file with proper asset structure.
32+
33+
- **Usage:**
34+
35+
```bash
36+
mkdocs-note new FILE_PATH [OPTIONS]
37+
```
38+
39+
- **Arguments:**
40+
41+
- `FILE_PATH` (required): Path where the new note file should be created
42+
43+
- **Features:**
44+
45+
- Automatically generates front matter metadata:
46+
47+
- `date`: Current timestamp in format `YYYY-MM-DD HH:MM:SS`
48+
49+
- `title`: Auto-generated from filename (converts `-` and `_` to spaces and title-cases)
50+
51+
- `permalink`: Empty by default
52+
53+
- `publish`: Set to `true` by default
54+
55+
- Creates corresponding asset directory automatically
56+
57+
- Ensures parent directories exist
58+
59+
- **Examples:**
60+
61+
```bash
62+
# Create a simple note
63+
mkdocs-note new docs/notes/my-note.md
64+
65+
# Create a note in nested directory
66+
mkdocs-note new docs/notes/python/intro.md
67+
68+
# Using template (feature planned)
69+
mkdocs-note new docs/notes/article.md --template templates/article.md
70+
```
71+
72+
- **Output:**
73+
74+
Upon successful creation, you'll see:
75+
76+
```
77+
✅ Successfully created note
78+
📝 Note: docs/notes/my-note.md
79+
📁 Assets: docs/notes/assets/my-note/
80+
```
81+
82+
### `remove`
83+
84+
Remove a note file and its corresponding asset directory.
85+
86+
- **Usage:**
87+
88+
```bash
89+
mkdocs-note remove FILE_PATH [OPTIONS]
90+
mkdocs-note rm FILE_PATH [OPTIONS] # Alias
91+
```
92+
93+
- **Arguments:**
94+
95+
- `FILE_PATH` (required): Path to the note file to remove
96+
97+
- **Options:**
98+
99+
- `--keep-assets`: Keep the asset directory when removing the note
100+
101+
- `--yes, -y`: Skip confirmation prompt
102+
103+
- **Features:**
104+
105+
- Removes both the note file and its corresponding asset directory by default
106+
- Supports removing single files or entire directories containing notes
107+
- Prompts for confirmation before deletion (unless `--yes` is used)
108+
- Automatically cleans up empty parent directories after removal
109+
- Supports both `.md` and `.ipynb` file formats
110+
111+
- **Examples:**
112+
113+
```bash
114+
# Remove a note with confirmation prompt
115+
mkdocs-note remove docs/notes/test.md
116+
117+
# Remove without confirmation
118+
mkdocs-note rm docs/notes/test.md --yes
119+
120+
# Remove note but keep its assets
121+
mkdocs-note remove docs/notes/test.md --keep-assets
122+
123+
# Remove all notes in a directory
124+
mkdocs-note rm docs/notes/drafts/
125+
```
126+
127+
- **Output:**
128+
129+
```
130+
✅ Successfully removed note: docs/notes/test.md
131+
📁 Removed assets: docs/notes/assets/test/
132+
```
133+
134+
### `move`
135+
136+
Move or rename a note file/directory and its corresponding asset directory.
137+
138+
- **Usage:**
139+
140+
```bash
141+
mkdocs-note move SOURCE DESTINATION [OPTIONS]
142+
mkdocs-note mv SOURCE DESTINATION [OPTIONS] # Alias
143+
```
144+
145+
- **Arguments:**
146+
147+
- `SOURCE` (required): Current path of the note file or directory
148+
149+
- `DESTINATION` (required): Destination path
150+
151+
- **Options:**
152+
153+
- `--keep-source-assets`: Keep the source asset directory (don't move it)
154+
155+
- `--yes, -y`: Skip confirmation prompt
156+
157+
- **Features:**
158+
159+
- Moves both the note file and its corresponding asset directory by default
160+
161+
- Supports moving single files or entire directories
162+
163+
- Automatically creates necessary parent directories
164+
165+
- Prompts for confirmation before moving (unless `--yes` is used)
166+
167+
- Cleans up empty parent directories at the source location
168+
169+
- Includes rollback mechanism if move operation fails
170+
171+
- Supports both `.md` and `.ipynb` file formats
172+
173+
- **Examples:**
174+
175+
```bash
176+
# Rename a note
177+
mkdocs-note move docs/notes/old-name.md docs/notes/new-name.md
178+
179+
# Move to different directory
180+
mkdocs-note mv docs/notes/draft.md docs/notes/published/
181+
182+
# Move entire directory
183+
mkdocs-note move docs/notes/drafts docs/notes/published --yes
184+
185+
# Move without moving assets
186+
mkdocs-note mv docs/notes/test.md docs/archive/test.md --keep-source-assets
187+
```
188+
189+
- **Output:**
190+
191+
```
192+
✅ Successfully moved
193+
📝 From: docs/notes/old-name.md
194+
📝 To: docs/notes/new-name.md
195+
📁 Assets moved
196+
```
197+
198+
### `clean`
199+
200+
Clean up orphaned asset directories without corresponding notes.
201+
202+
**Usage:**
203+
204+
```bash
205+
mkdocs-note clean [OPTIONS]
206+
```
207+
208+
- **Options:**
209+
210+
- `--dry-run`: Show what would be removed without actually removing
211+
212+
- `--yes, -y`: Skip confirmation prompt
213+
214+
- **Features:**
215+
216+
- Scans for asset directories that don't have corresponding note files
217+
218+
- Lists all orphaned directories before removal
219+
220+
- Supports dry-run mode to preview changes
221+
222+
- Prompts for confirmation before deletion (unless `--yes` is used)
223+
224+
- Automatically cleans up empty parent directories after removal
225+
226+
- Works recursively through the entire notes directory
227+
228+
- **Examples:**
229+
230+
```bash
231+
# Preview orphaned assets without removing
232+
mkdocs-note clean --dry-run
233+
234+
# Clean with confirmation
235+
mkdocs-note clean
236+
237+
# Clean without confirmation
238+
mkdocs-note clean --yes
239+
```
240+
241+
- **Output (dry-run):**
242+
243+
```
244+
🔍 Scanning for orphaned assets (dry run mode)...
245+
246+
Would remove 3 orphaned asset directories:
247+
📁 docs/notes/assets/deleted-note/
248+
📁 docs/notes/assets/old-draft/
249+
📁 docs/notes/python/assets/removed/
250+
251+
💡 Run without --dry-run to actually remove these directories
252+
```
253+
254+
- **Output (actual cleanup):**
255+
256+
```
257+
🔍 Scanning for orphaned assets...
258+
259+
Found 3 orphaned asset directories:
260+
📁 docs/notes/assets/deleted-note/
261+
📁 docs/notes/assets/old-draft/
262+
📁 docs/notes/python/assets/removed/
263+
264+
Remove these 3 directories? [y/N]: y
265+
266+
🗑️ Removing orphaned assets...
267+
✅ Successfully removed 3 orphaned asset directories
268+
```

0 commit comments

Comments
 (0)