Elektra  0.9.2
Plugin: gopts
  • infos = Information about the gopts plugin is in keys below
  • infos/author = Klemens Böswirth k.boe.nosp@m.swir.nosp@m.th+gi.nosp@m.t@gm.nosp@m.ail.c.nosp@m.om
  • infos/licence = BSD
  • infos/needs =
  • infos/provides =
  • infos/recommends =
  • infos/placements = procgetstorage
  • infos/status = recommended productive maintained nodep libc
  • infos/metadata = args args/index command opt opt/long opt/arg opt/flagvalue opt/help opt/hidden opt/# opt/#/long opt/#/arg opt/#/flagvalue opt/#/hidden env env/#
  • infos/description = Parses command-line options using elektra-opts

Introduction

This plugin is very simple in what it does. It uses system specific methods of accessing argc and argv outside of main and then calls elektraGetOpts to do options processing.

The config key /offset may be given to ignore a number of arguments at the start of argv. This is useful, if gopts was called from a script via an interpreter (e.g. in python scripts).

Usage

The preferred way of using this plugin is via kdbEnsure:

KDB * kdb = kdbOpen (parentKey);
KeySet * contract = ksNew (1, keyNew ("system/elektra/ensure/plugins/global/gopts", KEY_VALUE, "mounted", KEY_END), KS_END);
int rc = kdbEnsure (kdb, contract, parentKey);
if (rc != 0)
{
// error handling
}
// gopts now mounted
KeySet * ks = ksNew (0, KS_END);
kdbGet (kdb, ks, parentKey);

Help message

If elektraGetOpts determined that the application is in help mode (i.e. --help was used), gopts will set the key proc/elektra/gopts/help to 1. It will also invoke elektraGetOptsHelpMessage and write the result into the key proc/elektra/gopts/help/message. The usage and prefix values used for this call can be configured, via the /help/usage and /help/prefix config keys.

kdbGet
int kdbGet(KDB *handle, KeySet *ks, Key *parentKey)
Retrieve keys in an atomic and universal way.
Definition: kdb.c:1024
kdbOpen
KDB * kdbOpen(Key *errorKey)
Opens the session with the Key database.
Definition: kdb.c:290
ksNew
KeySet * ksNew(size_t alloc,...)
Allocate, initialize and return a new KeySet object.
Definition: keyset.c:225
kdbEnsure
int kdbEnsure(KDB *handle, KeySet *contract, Key *parentKey)
This function can be used to ensure the given KDB handle meets certain clauses, specified in contract...
Definition: kdb.c:2064
kdb
This is the main namespace for the C++ binding and libraries.
Definition: backend.hpp:30
KEY_VALUE
@ KEY_VALUE
Definition: kdbenum.c:23
KS_END
#define KS_END
End of a list of keys.
Definition: kdbenum.c:88
KEY_END
@ KEY_END
Definition: kdbenum.c:41
keyNew
Key * keyNew(const char *name,...)
A practical way to fully create a Key object in one step.
Definition: key.c:167