genfile 0.4.0

CLI for genfile_core template archive management - create, manage, and materialize code generation templates.
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
# GenFile CLI Tutorial

**Version:** 1.0.0
**Target Audience:** Beginners to intermediate users
**Prerequisites:** Basic command-line familiarity
**Time to Complete:** 45-60 minutes (all 4 lessons)

---

## Overview

This tutorial guides you through GenFile CLI fundamentals with hands-on examples. By the end, you'll understand:

1. **Lesson 1:** Archive basics (create, save, load)
2. **Lesson 2:** Working with files and templates
3. **Lesson 3:** Parameters and values for dynamic content
4. **Lesson 4:** Content management and real-world workflows

**Learning Path:** Each lesson builds on previous concepts. Complete them in order for best results.

---

## Lesson 1: Archive Basics (15 minutes)

### What You'll Learn

- Create and manage template archives
- Save and load archives from disk
- Understand archive operations

### Concepts

**What is a Template Archive?**

A template archive is a structured container for file templates with parameters and dynamic content. Think of it as a "smart directory" that can be saved, shared, and materialized with different values.

**Core Operations:**
- `.archive.new` - Create archive
- `.archive.save` - Write to disk
- `.archive.load` - Read from disk
- `.archive.close` - Reset current archive

### Exercise 1.1: Your First Archive

**Goal:** Create a simple archive and save it.

```bash
# Step 1: Create new archive named "my_first_archive"
genfile .archive.new name::"my_first_archive" description::"My first template archive" verbosity::2

# Expected output:
# ✓ Archive created: my_first_archive
# Description: My first template archive
# Status: Empty (0 files, 0 parameters)
```

**What happened?**
- Created archive in memory
- Set name and description
- `verbosity::2` shows detailed output

**Try this:** Change `verbosity::3` to see even more details.

### Exercise 1.2: Save and Load

**Goal:** Persist your archive to disk and reload it.

```bash
# Step 1: Save current archive to disk
genfile .archive.save path::"./my_first.genfile" verbosity::2

# Expected output:
# ✓ Archive saved: ./my_first.genfile
# Size: 245 bytes
# Format: TOML

# Step 2: Close current archive (clear memory)
genfile .archive.close verbosity::1

# Expected output:
# ✓ Archive closed

# Step 3: Reload from disk
genfile .archive.load path::"./my_first.genfile" verbosity::2

# Expected output:
# ✓ Archive loaded: ./my_first.genfile
# Name: my_first_archive
# Files: 0
# Parameters: 0
```

**What happened?**
1. Saved in-memory archive to TOML file
2. Cleared memory state
3. Restored archive from disk

**Checkpoint:** You now understand the archive lifecycle!

### Exercise 1.3: Dry Run Mode

**Goal:** Test operations without making changes.

```bash
# Create archive with dry run enabled
genfile .archive.new name::"test_archive" dry_run::true verbosity::2

# Expected output:
# [DRY RUN] Would create archive: test_archive
# [DRY RUN] No changes made

# Try saving (nothing written)
genfile .archive.save path::"./test.genfile" dry_run::true verbosity::2

# Expected output:
# [DRY RUN] Would save to: ./test.genfile
# [DRY RUN] No file written
```

**What happened?**
- `dry_run::true` simulates operations
- Nothing written to disk or memory
- Perfect for testing commands

**Pro Tip:** Always use `dry_run::true` when testing complex operations.

### Lesson 1 Review

**What you learned:**
- ✓ Create archives with `.archive.new`
- ✓ Save archives with `.archive.save`
- ✓ Load archives with `.archive.load`
- ✓ Test safely with `dry_run::true`

**Next:** Lesson 2 adds files to your archives.

---

## Lesson 2: Working with Files (15 minutes)

### What You'll Learn

- Add files to archives
- Use template variables
- Define file structure

### Concepts

**Template Files vs Regular Files:**

Template files contain placeholders like `{project_name}` that get replaced during materialization. Regular files are static content.

**File Operations:**
- `.file.add` - Add template with path and content
- `.file.remove` - Remove file from archive
- `.file.list` - Show all files in archive

### Exercise 2.1: Add Your First File

**Goal:** Create archive with a template README file.

```bash
# Step 1: Create new archive
genfile .archive.new name::"readme_template" verbosity::1

# Step 2: Add README template with placeholder
genfile .file.add \
  path::"readme.md" \
  content::"# {project_name}\n\nWelcome to {project_name}!\n\n## Description\n\n{description}" \
  verbosity::2

# Expected output:
# ✓ File added: readme.md
# Content size: 78 bytes
# Placeholders detected: project_name, description
# Archive status: 1 file, 0 parameters
```

**What happened?**
- Added `readme.md` template to archive
- Content includes `{project_name}` and `{description}` placeholders
- Placeholders detected but not yet defined

### Exercise 2.2: List Files

**Goal:** View all files in current archive.

```bash
genfile .file.list verbosity::2

# Expected output:
# Archive: readme_template
# Files (1):
#   [1] readme.md (78 bytes, 2 placeholders)
#       Placeholders: project_name, description
```

**What you see:**
- File count
- File path
- Content size
- Detected placeholders

### Exercise 2.3: Add Multiple Files

**Goal:** Create multi-file project template.

```bash
# Add main source file
genfile .file.add \
  path::"src/main.rs" \
  content::"fn main() {\n    println!(\"Hello from {project_name}!\");\n}" \
  verbosity::1

# Add configuration file
genfile .file.add \
  path::"config.toml" \
  content::"[project]\nname = \"{project_name}\"\nversion = \"{version}\"" \
  verbosity::1

# List all files
genfile .file.list verbosity::2

# Expected output:
# Archive: readme_template
# Files (3):
#   [1] readme.md (78 bytes)
#   [2] src/main.rs (56 bytes)
#   [3] config.toml (52 bytes)
# Total placeholders: project_name, description, version
```

**What happened?**
- Added 3 files to archive
- Each file can have different placeholders
- Archive now has structure: readme.md, src/, config.toml

### Exercise 2.4: Remove a File

**Goal:** Remove unwanted file from archive.

```bash
# Remove config file
genfile .file.remove path::"config.toml" verbosity::2

# Expected output:
# ✓ File removed: config.toml
# Archive status: 2 files remaining

# Verify removal
genfile .file.list verbosity::1

# Expected output:
# Files (2):
#   readme.md
#   src/main.rs
```

**What happened?**
- Removed `config.toml` from archive
- Other files unchanged
- Archive now has 2 files

### Exercise 2.5: Save Multi-File Archive

**Goal:** Persist your template for reuse.

```bash
# Save complete archive
genfile .archive.save path::"./project_template.genfile" verbosity::2

# Expected output:
# ✓ Archive saved: ./project_template.genfile
# Size: 1.2 KB
# Files: 2
# Format: TOML
```

**Checkpoint:** You can now create reusable file templates!

### Lesson 2 Review

**What you learned:**
- ✓ Add files with `.file.add`
- ✓ List files with `.file.list`
- ✓ Remove files with `.file.remove`
- ✓ Use placeholders like `{project_name}` in content
- ✓ Create multi-file templates

**Next:** Lesson 3 defines parameters for placeholders.

---

## Lesson 3: Parameters and Values (15 minutes)

### What You'll Learn

- Define parameters for placeholders
- Set parameter values
- Validate parameter constraints

### Concepts

**Parameters Define Placeholders:**

Every `{placeholder}` in your templates should have a corresponding parameter definition that specifies:
- Name (matches placeholder)
- Description (what it represents)
- Default value (optional)
- Optional flag (required vs optional)

**Parameter Operations:**
- `.parameter.define` - Create parameter definition
- `.parameter.list` - Show all parameters
- `.value.set` - Assign value to parameter
- `.value.list` - Show current values

### Exercise 3.1: Define Parameters

**Goal:** Define parameters for template placeholders.

```bash
# Load previous archive
genfile .archive.load path::"./project_template.genfile" verbosity::1

# Define project_name parameter (required)
genfile .parameter.define \
  name::"project_name" \
  description::"Name of the project" \
  optional::false \
  verbosity::2

# Expected output:
# ✓ Parameter defined: project_name
# Description: Name of the project
# Required: Yes
# Default: None

# Define description parameter with default
genfile .parameter.define \
  name::"description" \
  description::"Project description text" \
  optional::true \
  default::"A new project" \
  verbosity::2

# Expected output:
# ✓ Parameter defined: description
# Description: Project description text
# Required: No
# Default: "A new project"
```

**What happened?**
- Defined 2 parameters matching template placeholders
- `project_name` is required (no default)
- `description` is optional (has default)

### Exercise 3.2: List Parameters

**Goal:** View all defined parameters.

```bash
genfile .parameter.list verbosity::2

# Expected output:
# Archive: readme_template
# Parameters (2):
#   [1] project_name (required)
#       Description: Name of the project
#       Used in: readme.md, src/main.rs
#
#   [2] description (optional)
#       Description: Project description text
#       Default: "A new project"
#       Used in: readme.md
```

**What you see:**
- All defined parameters
- Required vs optional status
- Default values
- Which files use each parameter

### Exercise 3.3: Set Parameter Values

**Goal:** Assign values to parameters for materialization.

```bash
# Set project name
genfile .value.set \
  name::"project_name" \
  value::"my_awesome_app" \
  verbosity::2

# Expected output:
# ✓ Value set: project_name = "my_awesome_app"
# Status: Valid
# Required parameter: Satisfied

# Set custom description
genfile .value.set \
  name::"description" \
  value::"An amazing application" \
  verbosity::1

# List all values
genfile .value.list verbosity::2

# Expected output:
# Parameter Values (2):
#   project_name = "my_awesome_app"
#   description = "An amazing application"
#
# Validation: ✓ All required parameters set
```

**What happened?**
- Set values for both parameters
- Values validated against definitions
- Archive ready for materialization

### Exercise 3.4: Materialization Preview

**Goal:** See what files would be generated.

```bash
# Preview materialization (dry run)
genfile .materialize \
  output_dir::"./output" \
  dry_run::true \
  verbosity::3

# Expected output:
# [DRY RUN] Would create: ./output/readme.md
# Content preview:
# ---
# # my_awesome_app
#
# Welcome to my_awesome_app!
#
# ## Description
#
# An amazing application
# ---
#
# [DRY RUN] Would create: ./output/src/main.rs
# Content preview:
# ---
# fn main() {
#     println!("Hello from my_awesome_app!");
# }
# ---
#
# [DRY RUN] Summary:
# - 2 files would be created
# - 0 directories would be created
# - No actual changes made
```

**What you see:**
- Full preview of generated files
- All placeholders replaced with values
- Directory structure
- No files actually created (dry run)

**Checkpoint:** You understand the full parameter → value → materialization flow!

### Lesson 3 Review

**What you learned:**
- ✓ Define parameters with `.parameter.define`
- ✓ Set required vs optional parameters
- ✓ Assign values with `.value.set`
- ✓ Preview materialization with `dry_run::true`

**Next:** Lesson 4 covers real-world workflows.

---

## Lesson 4: Real-World Workflows (15 minutes)

### What You'll Learn

- Complete end-to-end workflows
- Content management strategies
- Archive organization patterns

### Concepts

**Production Workflow:**

1. Create or load archive
2. Define structure (files + parameters)
3. Set values for specific instance
4. Materialize to disk
5. Save archive for reuse

**Content Operations:**
- `.content.get` - Retrieve file content
- `.content.inspect` - Analyze content
- `.content.replace` - Update file content

### Exercise 4.1: Create Rust Project Template

**Goal:** Build reusable Rust project template from scratch.

```bash
# Step 1: Create archive
genfile .archive.new \
  name::"rust_binary_template" \
  description::"Template for Rust binary projects" \
  verbosity::2

# Step 2: Add Cargo.toml
genfile .file.add \
  path::"Cargo.toml" \
  content::"[package]\nname = \"{crate_name}\"\nversion = \"{version}\"\nedition = \"2021\"\n\n[dependencies]" \
  verbosity::1

# Step 3: Add main.rs
genfile .file.add \
  path::"src/main.rs" \
  content::"fn main()\n{\n  println!( \"Welcome to {crate_name} v{version}!\" );\n}" \
  verbosity::1

# Step 4: Add README
genfile .file.add \
  path::"readme.md" \
  content::"# {crate_name}\n\n{description}\n\n## Installation\n\n```bash\ncargo install {crate_name}\n```" \
  verbosity::1

# Step 5: Define parameters
genfile .parameter.define \
  name::"crate_name" \
  description::"Rust crate name" \
  optional::false \
  verbosity::1

genfile .parameter.define \
  name::"version" \
  description::"Initial version" \
  optional::true \
  default::"0.1.0" \
  verbosity::1

genfile .parameter.define \
  name::"description" \
  description::"Crate description" \
  optional::true \
  default::"A Rust binary application" \
  verbosity::1

# Step 6: Save reusable template
genfile .archive.save \
  path::"./templates/rust_binary.genfile" \
  verbosity::2

# Expected output:
# ✓ Archive saved: ./templates/rust_binary.genfile
# Files: 3 (Cargo.toml, src/main.rs, readme.md)
# Parameters: 3 (1 required, 2 optional)
# Ready for reuse
```

**What you created:**
- Complete Rust project template
- 3 files with proper structure
- 3 parameters (1 required, 2 with defaults)
- Saved for reuse

### Exercise 4.2: Use Template for New Project

**Goal:** Generate actual project from template.

```bash
# Step 1: Load template
genfile .archive.load \
  path::"./templates/rust_binary.genfile" \
  verbosity::1

# Step 2: Set values for specific project
genfile .value.set name::"crate_name" value::"hello_world" verbosity::1
genfile .value.set name::"version" value::"0.1.0" verbosity::1
genfile .value.set name::"description" value::"A friendly greeting app" verbosity::1

# Step 3: Preview (optional but recommended)
genfile .materialize \
  output_dir::"./hello_world" \
  dry_run::true \
  verbosity::2

# Step 4: Actually create files
genfile .materialize \
  output_dir::"./hello_world" \
  dry_run::false \
  verbosity::3

# Expected output:
# ✓ Created: ./hello_world/Cargo.toml
# ✓ Created: ./hello_world/src/main.rs
# ✓ Created: ./hello_world/readme.md
#
# Summary:
# - 3 files created
# - 1 directory created (src/)
# - Total size: 428 bytes
#
# Next steps:
# cd hello_world && cargo build
```

**What happened:**
1. Loaded reusable template
2. Customized for specific project
3. Generated complete project structure
4. Ready to build and run

**Try it:** Run `cd hello_world && cargo build && cargo run`

### Exercise 4.3: Content Management

**Goal:** Inspect and modify template content.

```bash
# Load template again
genfile .archive.load \
  path::"./templates/rust_binary.genfile" \
  verbosity::1

# Inspect main.rs content
genfile .content.get \
  path::"src/main.rs" \
  verbosity::2

# Expected output:
# File: src/main.rs
# Content (78 bytes):
# ---
# fn main()
# {
#   println!( "Welcome to {crate_name} v{version}!" );
# }
# ---
# Placeholders: crate_name, version

# Analyze content structure
genfile .content.inspect \
  path::"src/main.rs" \
  verbosity::3

# Expected output:
# File: src/main.rs
# Analysis:
#   Size: 78 bytes
#   Lines: 4
#   Placeholders: 2 (crate_name, version)
#   Language: Rust (detected from extension)
#   Syntax valid: Yes

# Update content
genfile .content.replace \
  path::"src/main.rs" \
  content::"fn main()\n{\n  println!( \"=== {crate_name} v{version} ===\"  );\n  println!( \"Status: Ready!\" );\n}" \
  verbosity::2

# Expected output:
# ✓ Content replaced: src/main.rs
# Old size: 78 bytes
# New size: 112 bytes
# Change: +34 bytes

# Save updated template
genfile .archive.save \
  path::"./templates/rust_binary.genfile" \
  verbosity::1
```

**What happened:**
- Retrieved file content
- Analyzed content structure
- Updated template
- Saved changes

### Exercise 4.4: Advanced Workflow

**Goal:** Combine operations for efficient workflow.

```bash
# One-liner: Create archive, add files, save
genfile .archive.new name::"quick_template" verbosity::0 && \
  genfile .file.add path::"file.txt" content::"Hello {name}!" verbosity::0 && \
  genfile .parameter.define name::"name" optional::false verbosity::0 && \
  genfile .archive.save path::"./quick.genfile" verbosity::1

# One-liner: Load, set values, materialize
genfile .archive.load path::"./quick.genfile" verbosity::0 && \
  genfile .value.set name::"name" value::"World" verbosity::0 && \
  genfile .materialize output_dir::"./output" verbosity::2

# Expected output:
# ✓ Created: ./output/file.txt
# Content: Hello World!
```

**What you learned:**
- Chain commands with `&&`
- Use `verbosity::0` for quiet mode
- Create rapid workflows

### Lesson 4 Review

**What you learned:**
- ✓ Build complete project templates
- ✓ Reuse templates for multiple projects
- ✓ Manage content with `.content.*` commands
- ✓ Chain commands for efficient workflows

**You're now proficient with GenFile CLI!**

---

## What's Next?

### Additional Resources

1. **[Commands Reference]commands.md** - Complete command documentation
2. **[Parameters Reference]params.md** - All parameter specifications
3. **[Type System]types.md** - For implementers and advanced users
4. **[Dictionary]dictionary.md** - Domain terminology

### Common Patterns

**Pattern 1: Team Template Library**
```bash
# Create shared templates directory
mkdir -p ~/.genfile/templates

# Save team templates
genfile .archive.save path::"~/.genfile/templates/rust_lib.genfile"
genfile .archive.save path::"~/.genfile/templates/react_component.genfile"

# Team members can load
genfile .archive.load path::"~/.genfile/templates/rust_lib.genfile"
```

**Pattern 2: Versioned Archives**
```bash
# Save with version in filename
genfile .archive.save path::"./templates/api_v1.0.0.genfile"
genfile .archive.save path::"./templates/api_v1.1.0.genfile"

# Load specific version
genfile .archive.load path::"./templates/api_v1.1.0.genfile"
```

**Pattern 3: Batch Materialization**
```bash
# Create multiple projects from same template
for project in app1 app2 app3; do
  genfile .archive.load path::"./template.genfile" verbosity::0
  genfile .value.set name::"project_name" value::"$project" verbosity::0
  genfile .materialize output_dir::"./$project" verbosity::1
done
```

### Practice Exercises

**Exercise A: Web API Template**

Create a template for REST API projects with:
- `server.py` with `{api_name}` and `{port}` placeholders
- `readme.md` with documentation
- `requirements.txt` with dependencies
- Parameters: api_name (required), port (default: 8000), description (optional)

**Exercise B: Multi-Language Template**

Create a template that generates the same project in multiple languages:
- `rust/` directory with Rust implementation
- `python/` directory with Python implementation
- Shared `readme.md`
- Parameter: `project_name`

**Exercise C: Archive Migration**

Practice loading, modifying, and resaving archives:
1. Load existing archive
2. Add new file
3. Update parameter definitions
4. Save as new version

### Getting Help

**Documentation:** All commands documented in [commands.md](commands.md)

**Examples:** See [commands/operations.md](commands/operations.md) for `.materialize` workflows

**Issues:** Common problems and solutions in MAINTENANCE.md

**Verbosity Levels:**
- `verbosity::0` - Silent (only errors)
- `verbosity::1` - Minimal (success/failure)
- `verbosity::2` - Standard (detailed info)
- `verbosity::3` - Verbose (all details)
- `verbosity::4` - Debug (internal state)
- `verbosity::5` - Trace (everything)

---

## Congratulations!

You've completed the GenFile CLI tutorial. You now understand:

- ✓ Archive lifecycle (create, save, load)
- ✓ File management (add, remove, list)
- ✓ Parameter definitions and values
- ✓ Content operations
- ✓ Complete workflows from template to materialization

**You're ready to create production templates!**

---

**Tutorial Version:** 1.0.0
**Last Updated:** 2026-02-08
**Feedback:** Report issues or suggestions via project repository