Skip to content

Commit

Permalink
kdb: add mountOdbc spec
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes99 committed Jul 5, 2023
1 parent fbcc5a1 commit fe6ba2e
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 2 deletions.
2 changes: 0 additions & 2 deletions doc/help/kdb-mountOdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ Use `kdb file system:/elektra/mountpoints` to find out where exactly it will wri
Show the man page.
- `-V`, `--version`:
Print version info.
- `-p`, `--profile <profile>`:
Use a different kdb profile.
- `-C`, `--color <when>`:
Print never/auto(default)/always colored output.
- `-v`, `--verbose`:
Expand Down
2 changes: 2 additions & 0 deletions src/tools/kdb/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <meta-set.h>
#include <meta-show.h>
#include <mount.h>
#include <mountOdbc.h>
#include <mv.h>
#include <namespace.h>
#include <plugin-check.h>
Expand Down Expand Up @@ -83,6 +84,7 @@ cppCommand cppSubcommands[] = {
{ "meta-rm", addMetaRmSpec, execCppMetaRm },
{ "meta-set", addMetaSetSpec, execCppMetaSet },
{ "meta-show", addMetaShowSpec, execCppMetaShow },
{ "mountOdbc", addMountOdbcSpec, execCppMountOdbc },
{ "mv", addMvSpec, execCppMv },
{ "namespace", addNamespaceSpec, execCppNamespace },
{ "rm", addRmSpec, execCppRm },
Expand Down
82 changes: 82 additions & 0 deletions src/tools/kdb/mountOdbc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @file
*
* @brief Implementation of kdb mount command
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/

#include <command.h>
#include <mountOdbc.h>

#include <kdb.h>

#include <cpp-main.h>

#define COMMAND_NAME "mountOdbc"

#define GET_OPTION_KEY(options, name) GET_OPT_KEY (options, COMMAND_BASE_KEY (COMMAND_NAME) "/" name)
#define GET_OPTION(options, name) GET_OPT (options, COMMAND_BASE_KEY (COMMAND_NAME) "/" name)

void addMountOdbcSpec (KeySet * spec)
{
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME), KEY_META, "description", "Mount a new backend.", KEY_META, "command",
COMMAND_NAME, KEY_END));

ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/data-source-name", KEY_META, "description",
"The name of the ODBC data source as defined in odbc.ini", KEY_META, "args", "indexed", KEY_META,
"args/index", "0", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/user-name", KEY_META, "description",
"The username that should be used for connecting to the ODBC data source. If no username is needed, or "
"it is already specified in the ini-file for the configuration of the datasource, \"\" can be provided "
"for this argument.",
KEY_META, "args", "indexed", KEY_META, "args/index", "1", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/password", KEY_META, "description",
"The same rules as for user name also apply to this argument.", KEY_META, "args", "indexed", KEY_META,
"args/index", "2", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/table-name", KEY_META, "description",
"The name of the table in the data source where the keys and their values should be stored.", KEY_META,
"args", "indexed", KEY_META, "args/index", "3", KEY_END));
ksAppendKey (spec,
keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/key-col-name", KEY_META, "description",
"The name of the column where the key-names should be stored. This should be the primary key of the table.",
KEY_META, "args", "indexed", KEY_META, "args/index", "4", KEY_END));
ksAppendKey (
spec,
keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/value-col-name", KEY_META, "description",
"The name of the column where the key-values (strings) should be stored. This column should support NULL-values.",
KEY_META, "args", "indexed", KEY_META, "args/index", "5", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/meta-table-name", KEY_META, "description",
"The name of the table where the metadata for the keys should be stored.", KEY_META, "args", "indexed",
KEY_META, "args/index", "6", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/mt-key-col-name", KEY_META, "description",
"The name of the column in the meta table where the key-name should be stored. This should be a foreign "
"key that refers to the column with the key-name of the other table.",
KEY_META, "args", "indexed", KEY_META, "args/index", "7", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/mt-metakey-col-name", KEY_META, "description",
"The name of the column in the meta table where the name of the metakey should be stored. This column, "
"together with the column for the key-name, should define the primary key of the meta table.",
KEY_META, "args", "indexed", KEY_META, "args/index", "8", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/mt-metavalue-col-name", KEY_META, "description",
"The name of the column in the meta table where the value (string) of the metakey should be stored. "
"This column should support NULL-values.",
KEY_META, "args", "indexed", KEY_META, "args/index", "9", KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/timeout", KEY_META, "description",
"The timeout (in seconds) that should be used when connecting to the data source. When passing '0', the "
"timeout gets disabled and the application could potentially wait forever. So use this option with "
"care! If you want to use a default timeout, you can just pass \"\" for this argument.",
KEY_META, "args", "indexed", KEY_META, "args/index", "10", KEY_END));
ksAppendKey (
spec,
keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/mountpoint", KEY_META, "description",
"The place in the KDB where the ODBC data source should be mounted. The syntax is the same as with the file-based "
"backend, but you can only use user:/ and system:/ namespaces as mountpoints for ODBC data sources.",
KEY_META, "args", "indexed", KEY_META, "args/index", "11", KEY_END));

ADD_BASIC_OPTIONS (spec, COMMAND_SPEC_KEY (COMMAND_NAME))
}

int execCppMountOdbc (int argc, char ** argv)
{
return cpp_main (argc, argv);
}
33 changes: 33 additions & 0 deletions src/tools/kdb/mountOdbc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file
*
* @brief Header for mountOdbc command
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/

#ifndef ELEKTRA_KDB_MOUNT_ODBC_H
#define ELEKTRA_KDB_MOUNT_ODBC_H

#include <kdb.h>

/**
* Adds options specification of mountOdbc command to @spec
*
* @param spec the base spec where the commands spec should be added
*/
void addMountOdbcSpec (KeySet * spec);

/**
* Executes the mountOdbc command
*
* @param options cli options and arguments as specified in addMountOdbcSpec()
* @param errorKey key where errors and warnings should be saved
*
* @retval 0 mountOdbc command ran without errors
* @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info
*
*/
int execCppMountOdbc (int argc, char ** argv);

#endif // ELEKTRA_KDB_MOUNT_ODBC_H

0 comments on commit fe6ba2e

Please sign in to comment.