Welcome to little lamb

Code » limb » release » tree

[release] / src / liblimb / command.h / dienocommand.c

/* This file is part of limb                           https://lila.oss/limb
 * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <unistd.h> /* _exit() */
#include <limb/command.h>
#include <limb/output.h>

void
dienocommand(int exit, const char *usage, const char *help)
{
    if (help) {
        errhelp(usage, help);
        err("Available commands:");
        char sp[17] = "                 ";
        for (unsigned i = 0; i < n_commands; ++i) {
            int n = sizeof(sp) - strlen(commands[i]->name);
            sp[n] = 0;
            err("  ", commands[i]->name, sp, commands[i]->desc);
            sp[n] = ' ';
        }
        _exit(0);
    } else {
        dieusage(exit, usage);
    }
}