libfossil
fcli_cliflag Struct Reference

Models a single CLI flag. More...

#include "cli.h"

Collaboration diagram for fcli_cliflag:

Data Fields

fcli_flag_callback_f callback
 Optional callback which gets passed the flag, if it is set, after fcli has assigned the flagValue entry (if it is not NULL).
const char * flagLong
 "Long-form" for this flag, noting that there's no restriction on its length.
const char * flagShort
 "Short-form" for this flag, noting that there's no restriction on its length.
enum fcli_cliflag_type_e flagType
 Specifies how to interpret the data pointed to by this->flagValue.
void * flagValue
 If not NULL, the member is the target of the flag's value.
const char * flagValueLabel
 Optional descriptive label to be used when rendering help text:
const char * helpText
 Help text for the flag.

Detailed Description

Models a single CLI flag.

Its relative complexity is largely to support generation of help text.

See also
fcli_process_flags()

Definition at line 168 of file cli.h.

Field Documentation

◆ callback

fcli_flag_callback_f fcli_cliflag::callback

Optional callback which gets passed the flag, if it is set, after fcli has assigned the flagValue entry (if it is not NULL).

See this data type's docs for more details.

Definition at line 246 of file cli.h.

◆ flagLong

const char* fcli_cliflag::flagLong

"Long-form" for this flag, noting that there's no restriction on its length.

Definition at line 179 of file cli.h.

◆ flagShort

const char* fcli_cliflag::flagShort

"Short-form" for this flag, noting that there's no restriction on its length.

Either of flagShort and flagLong, but not both, may be NULL.

Definition at line 174 of file cli.h.

◆ flagType

enum fcli_cliflag_type_e fcli_cliflag::flagType

Specifies how to interpret the data pointed to by this->flagValue.

See that member for details.

Definition at line 185 of file cli.h.

◆ flagValue

void* fcli_cliflag::flagValue

If not NULL, the member is the target of the flag's value.

Its exact interpretation depends on the value of this->flagType:

  • FCLI_FLAG_TYPE_BOOL: a pointer to a bool. Existence of the flag causes it to be set to true.
  • FCLI_FLAG_TYPE_BOOL_INVERT: a pointer to a bool, but existence of the flag causes it to be set to false.
  • FCLI_FLAG_TYPE_INT32: a pointer to an int32_t. The flag will be converted from string to int using atoi().
  • FCLI_FLAG_TYPE_INT64: a pointer to an int64_t. The flag will be converted from string to int using atoll().
  • FCLI_FLAG_TYPE_ID: a pointer to a fsl_id_t, which can be either int32_t or int64_t.
  • FCLI_FLAG_TYPE_DOUBLE: a pointer to a double. The flag will be converted from string to int using strtod().
  • FCLI_FLAG_TYPE_CSTR: a pointer to a (const char *). The flag's value will be assigned on without further interpretation.

If this member is not NULL: If the flag is set, this value will be assigned to. If the flag is not set in the CLI args, this value is not written to.

If this member is NULL then fcli_process_flags() will simply skip over it, but the help-text generator will process it. This can be used to set up flags which will appear in the –help text but which are processed separately (or outright ignored) by the app.

The underlying flag value's string memory is owned by fcli and is valid until the app exits.

Definition at line 224 of file cli.h.

◆ flagValueLabel

const char* fcli_cliflag::flagValueLabel

Optional descriptive label to be used when rendering help text:

-x|–x-flag=ABCD

If it is NULL, the –help text generator will choose a value of the ABCD part which depends on this->flagType.

This is only used if this->flagType is not one of (FCLI_FLAG_TYPE_BOOL, FCLI_FLAG_TYPE_BOOL_INVERT). For those types (which have no client-given values), this member is ignored when generating help text.

Definition at line 239 of file cli.h.

◆ helpText

const char* fcli_cliflag::helpText

Help text for the flag.

Intended to be displayed in the context of a –help listing of flags.

Definition at line 252 of file cli.h.


The documentation for this struct was generated from the following file: