aboutsummaryrefslogtreecommitdiff
path: root/cli/cli.h
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2025-09-13 01:37:55 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2025-09-13 01:37:55 +0300
commit312c20f2c868d8fdc014108152cc7782ae6ec90b (patch)
treeab21c2182b739cb91290cd0727b4d6b5c5364305 /cli/cli.h
parent8c73413201a720dd24451b468155069f954dfd35 (diff)
downloadc-wares-312c20f2c868d8fdc014108152cc7782ae6ec90b.tar.gz
c-wares-312c20f2c868d8fdc014108152cc7782ae6ec90b.zip
clang-format: align with spaces
Also format cli after the changes.
Diffstat (limited to 'cli/cli.h')
-rw-r--r--cli/cli.h60
1 files changed, 30 insertions, 30 deletions
diff --git a/cli/cli.h b/cli/cli.h
index 00848e8..7a7183c 100644
--- a/cli/cli.h
+++ b/cli/cli.h
@@ -46,8 +46,8 @@ enum cli_rc {
*/
struct cli_ctx {
struct cli_opt **opts;
- int argc;
- char *const *argv;
+ int argc;
+ char *const *argv;
};
/**
@@ -75,16 +75,16 @@ enum cli_opt_type : uint8_t {
*/
struct cli_opt {
enum cli_opt_type type;
- char shor;
- const char *lon;
- const char *desc;
+ char shor;
+ const char *lon;
+ const char *desc;
[[gnu::nonnull(1)]]
int (*set)(struct cli_opt *self, const char *val);
};
struct cli_opt_long {
struct cli_opt opt;
- long value;
+ long value;
};
#define CLI_OPT_LONG(name, sh, ln, dsc) \
@@ -103,7 +103,7 @@ int cli_opt_long_set(struct cli_opt *self, const char *val)
{
struct cli_opt_long *opt = container_of(self, struct cli_opt_long, opt);
- errno = 0;
+ errno = 0;
opt->value = strtol(val, NULL, 0);
if (errno != 0)
return CLI_RC_BAD_ARGS;
@@ -113,7 +113,7 @@ int cli_opt_long_set(struct cli_opt *self, const char *val)
struct cli_opt_ulong {
struct cli_opt opt;
- long value;
+ long value;
};
#define CLI_OPT_ULONG(name, sh, ln, dsc) \
@@ -132,7 +132,7 @@ int cli_opt_ulong_set(struct cli_opt *self, const char *val)
{
struct cli_opt_ulong *opt = container_of(self, struct cli_opt_ulong, opt);
- errno = 0;
+ errno = 0;
opt->value = strtoul(val, NULL, 0);
if (errno != 0)
return CLI_RC_BAD_ARGS;
@@ -142,7 +142,7 @@ int cli_opt_ulong_set(struct cli_opt *self, const char *val)
struct cli_opt_string {
struct cli_opt opt;
- const char *value;
+ const char *value;
};
#define CLI_OPT_STRING(name, sh, ln, dsc) \
@@ -170,7 +170,7 @@ int cli_opt_string_set(struct cli_opt *self, const char *val)
struct cli_opt_flag {
struct cli_opt opt;
- bool value;
+ bool value;
};
#define CLI_OPT_FLAG(name, sh, ln, dsc) \
@@ -188,7 +188,7 @@ struct cli_opt_flag {
int cli_opt_flag_set(struct cli_opt *self, const char *)
{
struct cli_opt_flag *opt = container_of(self, struct cli_opt_flag, opt);
- opt->value = true;
+ opt->value = true;
return CLI_RC_OK;
}
@@ -208,10 +208,10 @@ int cli_opt_flag_set(struct cli_opt *self, const char *)
* parsed from the command-line arguments.
*/
struct cli_cmd {
- const char *name;
- const char *desc;
- const char *usage;
- const char *help;
+ const char *name;
+ const char *desc;
+ const char *usage;
+ const char *help;
struct cli_opt **opts;
[[gnu::nonnull]]
int (*run)(const struct cli_cmd *self, const struct cli_ctx *ctx);
@@ -226,11 +226,11 @@ struct cli_cmd {
* @opts: array of global options; also requires a sentinel; can be NULL.
*/
struct cli {
- const char *binary;
- const char *header;
- const char *footer;
+ const char *binary;
+ const char *header;
+ const char *footer;
const struct cli_cmd *cmds;
- struct cli_opt **opts;
+ struct cli_opt **opts;
};
[[gnu::nonnull]]
@@ -265,8 +265,8 @@ static void explain_program(const struct cli *const cli)
printf("%s\n", cli->header);
printf("Usage: %s%s <command> [command options]\n\n",
- cli->opts ? "[global options] " : "",
- cli->binary);
+ cli->opts ? "[global options] " : "",
+ cli->binary);
if (cli->cmds) {
puts("Commands:");
@@ -290,16 +290,16 @@ static void explain_program(const struct cli *const cli)
[[gnu::nonnull]]
static void explain_command(const struct cli *const cli,
- const struct cli_cmd *cmd)
+ const struct cli_cmd *cmd)
{
if (cli->header)
printf("%s\n", cli->header);
printf("Usage: %s%s %s %s\n\n",
- cli->opts ? "[global options] " : "",
- cli->binary,
- cmd->name,
- cmd->usage ?: "[options]");
+ cli->opts ? "[global options] " : "",
+ cli->binary,
+ cmd->name,
+ cmd->usage ?: "[options]");
printf("%s\n\n", cmd->help);
if (cmd->opts) {
@@ -314,7 +314,7 @@ static void explain_command(const struct cli *const cli,
[[gnu::nonnull]]
static int parse_long(struct cli_ctx *ctx)
{
- char *key = ctx->argv[0] + 2;
+ char *key = ctx->argv[0] + 2;
const char *value = NULL;
for (size_t i = 0; i < strlen(key); i++) {
@@ -453,8 +453,8 @@ static int parse_options(struct cli_ctx *ctx)
[[gnu::nonnull]]
static inline int cli_cmd_run(const struct cli *const cli,
- const struct cli_cmd *cmd,
- const struct cli_ctx *global_ctx)
+ const struct cli_cmd *cmd,
+ const struct cli_ctx *global_ctx)
{
struct cli_ctx cmd_ctx = {
.opts = cmd->opts,