AtlatestRepositorysigil-doc

sigil-doc / tree / book / practical-sigil02-change-the-question.sgd

1#lang sigil/doc/book
2@chapter["Change the Question" authors: '("David Wilson")]
3
4@section["Turn a Script into a Tool" id: "script-into-tool"]
5
6@p {
7The first version in @ref ["first-script"] {A Useful First Script} answers one
8fixed question. A practical tool becomes more valuable when its user can choose
9the question without editing source code.
12@code["sigil"]
13(define state
14 (if (null? (command-line))
15 "TODO"
16 (car (command-line))))
17@end code
19Keeping this decision near the program boundary leaves parsing, counting, and
20reporting as ordinary reusable functions. The command line selects policy; the
21rest of the script remains simple data transformation.
23@end section
25@section["Craft the Interface" id: "craft-the-interface"]
27An interface is more than argument parsing. It includes useful defaults, clear
28failure messages, and output that composes well with other tools. Sigil lets us
29add those pieces without changing languages or abandoning the compact Scheme
30core that made the first script pleasant to write.
32Prefer one obvious default before adding flags. A tool that does something
33useful with no ceremony is easier to learn and easier to automate.
35@exercise["helpful-failure" "Craft a helpful failure"] {
36@p {
37Reject unknown states with a message that shows the accepted values and exits
38with a nonzero status. Keep that policy at the boundary rather than mixing it
39into @code{count-tasks}.
43@end section
44@end chapter