-static struct opt_section help = {
- OPT_ITEMS {
- OPT_HELP("A simple tea boiling console."),
- OPT_HELP("Usage: teapot [options] name-of-the-tea"),
- OPT_HELP("Black, green or white tea supported as well as fruit or herbal tea."),
- OPT_HELP("You may specify more kinds of tea, all of them will be boiled for you, in the given order."),
- OPT_HELP(""),
- OPT_HELP("Options:"),
- OPT_SHOW_HELP,
- OPT_CALL('V', "version", show_version, OPT_NO_VALUE, "Show the version"),
- OPT_HELP(""),
- OPT_BOOL('e', "english-style", english, 0, "English style (with milk)"),
- OPT_UNS('s', "sugar", sugar, OPT_REQUIRED_VALUE, "Amount of sugar (in teaspoons)"),
- OPT_SWITCH(0, "standard-set", set, TEAPOT_STANDARD, 0, "Standard teapot"),
- OPT_SWITCH('x', "exclusive-set", set, TEAPOT_EXCLUSIVE, 0, "Exclusive teapot"),
- OPT_SWITCH('g', "glass-set", set, TEAPOT_GLASS, 0, "Transparent glass teapot"),
- OPT_SWITCH('h', "hands", set, TEAPOT_HANDS, 0, "Use user's hands as a teapot (a bit dangerous)"),
- OPT_USER('t', "temperature", temperature, teapot_temperature_t, OPT_REQUIRED_VALUE, "Wanted final temperature of the tea to be served"),
- OPT_HELP2("", "Supported scales: Celsius [60C], Fahrenheit [140F],"),
- OPT_HELP2("", " Kelvin [350K], Rankine [600R] and Reaumur [50Re]"),
- OPT_HELP2("", "Only integer values allowed."),
- OPT_INC('v', "verbose", verbose, 0, "Verbose (the more -v, the more verbose)"),
- OPT_INC('q', "quiet", verbose, OPT_DECREMENT, "Quiet (the more -q, the more quiet)"),
- OPT_UNS('b', "black-magic", black_magic, 0, "Use black magic to make the tea extraordinary delicious"),
- OPT_BOOL('p', "pray", pray, 0, "Pray before boiling"),
- OPT_HELP(""),
- OPT_HELP("Water options:"),
- OPT_SECTION(water_options),
- OPT_END
+static void opt_check_required(struct opt_context *oc)
+{
+ for (int i = 0; i < oc->opt_count; i++) {
+ struct opt_precomputed *opt = &oc->opts[i];
+ if (!opt->count && (opt->flags & OPT_REQUIRED)) {
+ struct opt_item *item = opt->item;
+ if (item->letter > OPT_POSITIONAL_TAIL)
+ opt_failure("Required positional argument #%d not found.", item->letter - OPT_POSITIONAL_TAIL);
+ else if (item->letter == OPT_POSITIONAL_TAIL)
+ opt_failure("Required positional argument not found.");
+ else if (item->letter && item->name)
+ opt_failure("Required option -%c/--%s not found.", item->letter, item->name);
+ else if (item->letter)
+ opt_failure("Required option -%c not found.", item->letter);
+ else
+ opt_failure("Required option --%s not found.", item->name);
+ }