rl_lang/docs/entries/tutorial/t2/
p_b13.rs1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static ADV_HELP_POLISH: ConceptEntry = ConceptEntry {
4 name: "13. help and polish",
5 summary: "help and polish",
6 category: ConceptCategory::Tooling,
7 prerequisites: &[],
8 descriptions: &[
9 DescriptionEntry {
10 kind: DescriptionKind::Explanation,
11 title: None,
12 description: "help should print every available command with a short description. store the help text as a constant array of strings - one entry per command - and loop over it to print",
13 examples: &[
14 "CONST arr[string] HELP_LINES = [\n \" add <text> add a new task\",\n \" done <id> mark a task as done\",\n \" remove <id> delete a task\",\n \" list show all tasks\",\n \" list done show completed tasks\",\n \" list pending show pending tasks\",\n \" clear remove all completed tasks\",\n \" stats show task counts\",\n \" help show this message\",\n \" quit exit the program\",\n]\n\nfn cmd_help() {\n println(\"commands:\")\n for line in HELP_LINES {\n println(line)\n }\n}",
15 ],
16 expected_output: &[],
17 },
18 DescriptionEntry {
19 kind: DescriptionKind::Explanation,
20 title: None,
21 description: "unknown commands should not silently do nothing. print a helpful message pointing the user to help",
22 examples: &[
23 "// at the end of the dispatch chain:\n} else {\n println(format(\"unknown command: '{}'. type 'help' for commands\", cmd))\n}",
24 ],
25 expected_output: &[],
26 },
27 DescriptionEntry {
28 kind: DescriptionKind::Explanation,
29 title: None,
30 description: "on startup show a summary so the user immediately knows what state they are in. this uses the same stats logic but formatted as a one-liner",
31 examples: &[
32 "fn print_startup_summary(arr[arr[string]] tasks) {\n dec int total = len(tasks)\n dec int pending = len(csv_filter_by(tasks, COL_STATUS, \"pending\"))\n println(format(\"task manager ready - {} task(s), {} pending. type 'help' for commands\", total, pending))\n}",
33 ],
34 expected_output: &[],
35 },
36 DescriptionEntry {
37 kind: DescriptionKind::Explanation,
38 title: None,
39 description: "exercise: add help, unknown command handling, and the startup summary. run the full program and make sure every command works end to end",
40 examples: &[
41 "// startup\nprint_startup_summary(tasks)\n\n// in dispatch:\n} else if (cmd == \"help\") {\n cmd_help()\n} else {\n println(format(\"unknown command: '{}'. type 'help' for commands\", cmd))\n}",
42 ],
43 expected_output: &[],
44 },
45 ],
46 pitfalls: &[],
47 related: &[],
48 related_stdlib: &[],
49 since: None,
50};