Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Kdb cli rewrite #4807

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,9 @@ This section keeps you up-to-date with the multi-language support provided by El

## Tools

### <<Tool>>
### KDB

- <<TODO>>
- <<TODO>>
- <<TODO>>
- rewrite C++ cli to C _(@hannes99)_

### <<Tool>>

Expand Down
5 changes: 3 additions & 2 deletions src/tools/kdb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
include (LibAddMacros)

file (GLOB HDR_FILES *.hpp gen/*.hpp gen/*/*.hpp)
file (GLOB HDR_FILES *.h gen/*.hpp gen/*/*.hpp)
add_headers (HDR_FILES)
add_cppheaders (HDR_FILES)
add_toolheaders (HDR_FILES)
include_directories (${CMAKE_CURRENT_SOURCE_DIR})

file (GLOB SRC_FILES *.cpp gen/*.cpp gen/*/*.cpp)
file (GLOB SRC_FILES *.c gen/*.cpp gen/*/*.cpp)
list (REMOVE_ITEM SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/gen/templates/collect.cpp")
set (SOURCES ${SRC_FILES} ${HDR_FILES})

Expand All @@ -28,6 +28,7 @@ if (BUILD_SHARED)
elektra-core
elektra-kdb
elektratools
elektra-invoke
elektra-opts
elektra-merge)

Expand Down
53 changes: 53 additions & 0 deletions src/tools/kdb/basename.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @file
*
* @brief Implementation of kdb basename command
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/

#include <basename.h>
#include <command.h>

#include <kdb.h>
#include <kdbassert.h>
#include <kdbease.h>
#include <kdberrors.h>
#include <stdio.h>
#include <string.h>

#define COMMAND_NAME "basename"

#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 addBasenameSpec (KeySet * spec)
{
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME), KEY_META, "description", "Get the basename of a key.", KEY_META,
"command", COMMAND_NAME, KEY_END));
ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/name", KEY_META, "description", "The name of the key", KEY_META,
"args", "indexed", KEY_META, "args/index", "0", KEY_END));

ADD_BASIC_OPTIONS (spec, COMMAND_SPEC_KEY (COMMAND_NAME))
}

int execBasename (KeySet * options, Key * errorKey)
{
GET_BASIC_OPTIONS

const char * name = getKeyNameFromOptions (options, GET_OPTION (options, "name"), errorKey, verbose);
if (name == NULL) return 1;

Key * key = keyNew (name, KEY_END);
if (key == NULL)
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "'%s' is not a valid key name.", name);
elektraFree ((void *) name);
return 1;
}
CLI_PRINT (CLI_LOG_NONE, "%s", BOLD (keyBaseName (key)));

elektraFree ((void *) name);
keyDel (key);
return 0;
}
27 changes: 0 additions & 27 deletions src/tools/kdb/basename.cpp

This file was deleted.

33 changes: 33 additions & 0 deletions src/tools/kdb/basename.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file
*
* @brief Header for basename command
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/

#ifndef ELEKTRA_KDB_BASENAME_H
#define ELEKTRA_KDB_BASENAME_H

#include <kdb.h>

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

/**
* Executes the basename command
*
* @param options cli options and arguments as specified in @addBasenameSpec()
* @param errorKey key where errors and warnings should be saved
*
* @retval 0 ls command ran without errors
* @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info
*
*/
int execBasename (KeySet * options, Key * errorKey);

#endif // ELEKTRA_KDB_BASENAME_H
47 changes: 0 additions & 47 deletions src/tools/kdb/basename.hpp

This file was deleted.

Loading