tui-checkbox 0.4.4

A customizable checkbox widget for Ratatui TUI applications
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# Justfile Best Practices & Patterns

This document describes the patterns and best practices used in this project's `justfile`.

## Table of Contents

- [Getting Started]#getting-started
- [Fail Early Pattern]#fail-early-pattern
- [Command Dependencies]#command-dependencies
- [Naming Conventions]#naming-conventions
- [Common Patterns]#common-patterns

## Getting Started

### Automatic Setup

Run the interactive setup script to create or enhance your justfile:

```bash
./scripts/setup-just.sh
```

This script will:
- **Install `just`** if not already installed (via cargo or system package managers)
- **Create a new justfile** if one doesn't exist, with common commands for your project type
- **Enhance existing justfile** by adding missing useful commands (optional)
- **Install optional tools** like git-cliff for changelog generation
- **Set up shell completion** for better developer experience
- **Create backups** before modifying any files
- **Implement fail-early pattern** for version bumping and releases

The setup script detects your project type (Rust, Node.js, etc.) and creates appropriate commands automatically.

### Manual Creation

If you prefer to create a justfile manually, start with:

```just
# Default task - show available commands
default:
    @just --list
```

Then add commands specific to your project's needs.

## Fail Early Pattern

### Overview

The "fail early" pattern ensures that quality checks pass **before** making any permanent changes like version bumps or releases. This prevents creating broken releases and keeps the git history clean.

### Implementation

```just
# ❌ BAD: No checks before version bump
bump version:
    @./scripts/bump_version.sh {{version}}

# ✅ GOOD: Run all checks first
bump version: check-all check-git-cliff
    @./scripts/bump_version.sh {{version}}
```

### Why This Matters

1. **Prevents broken releases**: Code must pass all tests before tagging
2. **Keeps git history clean**: No need for "fix broken release" commits
3. **Saves time**: Fail fast instead of discovering issues after pushing
4. **Enforces quality**: Makes checks mandatory, not optional

### Dependency Chain

```
just bump 0.2.0
check-all
    ├── fmt-check  (verify code is formatted)
    ├── clippy     (check for lint issues)
    └── test       (run all tests)
check-git-cliff (verify changelog tool is installed)
bump_version.sh (actually bump the version)
```

If **any** step fails, the entire process stops immediately.

### Complete Example

```just
# Check if code is formatted
fmt-check:
    cargo fmt --check

# Run clippy linter
clippy:
    cargo clippy -- -D warnings

# Run tests
test:
    cargo test

# Run all checks (fail early pattern)
check-all: fmt-check clippy test
    @echo "✅ All checks passed!"

# Check if git-cliff is installed
check-git-cliff:
    @command -v git-cliff >/dev/null 2>&1 || { echo "❌ git-cliff not found"; exit 1; }

# Bump version (runs checks first)
bump version: check-all check-git-cliff
    @./scripts/bump_version.sh {{version}}

# Release (depends on bump, which depends on check-all)
release version: (bump version)
    git push origin main
    git push origin v{{version}}
```

## Command Dependencies

### Basic Syntax

Just uses dependencies to run commands in order:

```just
# command: dependency1 dependency2
release version: bump push
    @echo "Release complete!"
```

### Chaining Dependencies

Commands can depend on other commands that have their own dependencies:

```just
check-all: fmt-check clippy test

bump version: check-all check-git-cliff
    @./scripts/bump_version.sh {{version}}

release version: (bump version)
    git push origin main
    git push origin v{{version}}
```

Here `release` → `bump` → `check-all` → `fmt-check`, `clippy`, `test`

### Parameterized Dependencies

Use parentheses for dependencies that take parameters:

```just
# Pass the version parameter to bump
release version: (bump version)
    git push origin v{{version}}
```

## Naming Conventions

### Command Names

- Use **kebab-case**: `check-all`, `fmt-check`, `push-all`
- Be descriptive: `release-gitea` instead of `rel-g`
- Group related commands: `push`, `push-gitea`, `push-all`

### Parameter Names

- Use **snake_case** for parameters: `{{version}}`, `{{gitea_url}}`
- Make them self-documenting: `{{message}}` instead of `{{msg}}`

### Command Groups

Organize commands by prefix:

```just
# Building
build
build-release

# Testing
test
test-coverage

# Formatting
fmt
fmt-check

# Git operations
pull
pull-gitea
pull-all
push
push-gitea
push-all
```

## Common Patterns

### 1. Default Command

Always provide a helpful default:

```just
# Default task - show available commands
default:
    @just --list
```

### 2. Check Commands

Separate checking from fixing:

```just
# Format code
fmt:
    cargo fmt

# Check if code is formatted (read-only)
fmt-check:
    cargo fmt --check
```

### 3. Aggregate Commands

Create convenience commands that run multiple related tasks:

```just
# Run all checks
check-all: fmt-check clippy test
    @echo "✅ All checks passed!"
```

### 4. Tool Verification

Check for required tools before using them:

```just
# Check if git-cliff is installed
check-git-cliff:
    @command -v git-cliff >/dev/null 2>&1 || { echo "❌ git-cliff not found"; exit 1; }

# Use the check as a dependency
changelog: check-git-cliff
    git-cliff -o CHANGELOG.md
```

### 5. Silent Commands

Use `@` prefix to hide command echo (cleaner output):

```just
# ❌ Shows: echo "Building..." then the message
version:
    echo "Version 0.1.0"

# ✅ Only shows: Version 0.1.0
version:
    @echo "Version 0.1.0"
```

### 6. Parameterized Commands

Document parameters in comments:

```just
# Bump version (usage: just bump 0.2.0)
bump version: check-all
    @./scripts/bump_version.sh {{version}}

# Commit with message (usage: just commit "Add feature")
commit message:
    git commit -m "{{message}}"
```

### 7. Multi-Remote Git Operations

Support multiple git remotes gracefully:

```just
# Pull from GitHub
pull:
    git pull origin main

# Pull from Gitea
pull-gitea:
    git pull gitea main

# Pull from both remotes
pull-all:
    git pull gitea main
    git pull origin main
    @echo "✅ Pulled from both remotes!"

# Push to GitHub
push:
    git push origin main

# Push to Gitea
push-gitea:
    git push gitea main

# Push to both remotes
push-all:
    git push origin main
    git push gitea main
    @echo "✅ Pushed to both remotes!"
```

### 8. Version Information

Display project metadata:

```just
# Show current version
version:
    @grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/'

# Show project information
info:
    @echo "Project: $(grep '^name = ' Cargo.toml | head -1 | sed 's/name = "\(.*\)"/\1/')"
    @grep '^version = ' Cargo.toml | head -1 | sed 's/version = /Version: /' | tr -d '"'
```

## Release Workflow Pattern

A complete release workflow with fail-early checks:

```just
# 1. Check all code quality (fail early)
check-all: fmt-check clippy test
    @echo "✅ All checks passed!"

# 2. Verify tools are available
check-git-cliff:
    @command -v git-cliff >/dev/null 2>&1 || { echo "❌ git-cliff not found"; exit 1; }

# 3. Bump version (depends on checks)
bump version: check-all check-git-cliff
    @./scripts/bump_version.sh {{version}}

# 4. Release to GitHub (depends on bump)
release version: (bump version)
    git push origin main
    git push origin v{{version}}
    @echo "✅ Released v{{version}} to GitHub!"

# 5. Release to Gitea (depends on bump)
release-gitea version: (bump version)
    git push gitea main
    git push gitea v{{version}}
    @echo "✅ Released v{{version}} to Gitea!"

# 6. Release to all remotes (depends on bump)
release-all version: (bump version)
    git push origin main
    git push gitea main
    git push origin v{{version}}
    git push gitea v{{version}}
    @echo "✅ Released v{{version}} to all remotes!"
```

### Workflow Benefits

1. **Single command releases**: `just release-all 0.2.0`
2. **Automatic quality checks**: Can't release broken code
3. **Consistent process**: Same steps every time
4. **Clear dependencies**: Easy to understand what happens when

## Tips & Tricks

### Debugging

Show what a command will do without running it:

```bash
just --dry-run release 0.2.0
```

### Documentation

View the recipe for a command:

```bash
just --show release
```

### List Commands

```bash
just --list
# or simply
just
```

### Evaluate Variables

```bash
just --evaluate version
```

### Completion

Set up shell completion for better DX:

```bash
# Bash
mkdir -p ~/.local/share/bash-completion/completions
just --completions bash > ~/.local/share/bash-completion/completions/just

# Zsh
mkdir -p ~/.zsh/completion
just --completions zsh > ~/.zsh/completion/_just
# Add to ~/.zshrc: fpath=(~/.zsh/completion $fpath)

# Fish
just --completions fish > ~/.config/fish/completions/just.fish

# PowerShell
just --completions powershell > (Join-Path $PROFILE.CurrentUserAllHosts '..' Completions just-completion.ps1)
```

Or use the setup script: `./scripts/setup-just.sh`

## Project-Specific Commands

### Rust Projects

```just
# Build
build:
    cargo build

build-release:
    cargo build --release

# Test
test:
    cargo test

# Format
fmt:
    cargo fmt

fmt-check:
    cargo fmt --check

# Lint
clippy:
    cargo clippy -- -D warnings

# Documentation
doc:
    cargo doc --no-deps --open

# Clean
clean:
    cargo clean
```

### Node.js Projects

```just
# Install dependencies
install:
    npm install

# Build
build:
    npm run build

# Test
test:
    npm test

# Lint
lint:
    npm run lint

# Format
fmt:
    npm run format

fmt-check:
    npm run format:check
```

### Python Projects

```just
# Setup virtual environment
venv:
    python -m venv venv

# Install dependencies
install:
    pip install -r requirements.txt

# Test
test:
    pytest

# Lint
lint:
    ruff check .

# Format
fmt:
    black .

fmt-check:
    black --check .
```

## References

- [Official just documentation]https://just.systems/man/en/
- [GitHub repository]https://github.com/casey/just
- [Setup script]../scripts/setup-just.sh - Automated installation and configuration

## Contributing

When adding new commands to the justfile:

1. ✅ Follow the naming conventions
2. ✅ Use the fail-early pattern for destructive operations
3. ✅ Add descriptive comments
4. ✅ Group related commands together
5. ✅ Test dependencies work correctly
6. ✅ Update this documentation if introducing new patterns

## Auto-Generation

The `setup-just.sh` script can automatically generate a justfile with common commands based on your project type. It will:

- Detect if your project is Rust, Node.js, Python, etc.
- Create appropriate build, test, and check commands
- Implement the fail-early pattern for version bumping
- Add git operations for multiple remotes
- Include documentation and info commands

Run `./scripts/setup-just.sh` to get started!