This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
... and remove cpp implementation
- Loading branch information
Showing
6 changed files
with
100 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @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) | ||
{ | ||
bool verbose = false; | ||
Key * tmp = GET_OPTION_KEY (options, "verbose"); | ||
if (tmp != NULL) | ||
{ | ||
elektraKeyToBoolean (GET_OPTION_KEY (options, "verbose"), &verbose); | ||
} | ||
|
||
const char * rawName = GET_OPTION (options, "name"); | ||
bool resolved = false; | ||
const char * name = expandKeyName (options, rawName, &resolved); | ||
if (name == NULL) | ||
{ | ||
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "could not resolve bookmark in '%s'", rawName); | ||
return -1; | ||
} | ||
|
||
if (verbose && resolved) | ||
{ | ||
printf ("resolved bookmark: \'%s\' -> \'%s\'\n", rawName, name); | ||
} | ||
|
||
Key * key = keyNew (name, KEY_END); | ||
if (key == NULL) | ||
{ | ||
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "'%s' is not avlid key name.", name); | ||
return 1; | ||
} | ||
printf ("%s", keyBaseName (key)); | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters