From a2b15389b09f0b602f952fe8e2c2443c27a1189e Mon Sep 17 00:00:00 2001 From: Alessandro-Salerno Date: Sun, 10 Nov 2024 17:12:00 +0100 Subject: [PATCH] added version command --- Makefile | 2 + include/cli/directives/commands.h | 2 + src/common/cli/directives/commands/version.c | 58 ++++++++++++++++++++ src/common/cli/directives/lookup.c | 7 +++ 4 files changed, 69 insertions(+) create mode 100644 src/common/cli/directives/commands/version.c diff --git a/Makefile b/Makefile index 9c26b79..677ad80 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,8 @@ ifeq ($(OS),Windows_NT) EXEC+=.exe endif +CFLAGS+=-DEXT_TARMAN_OS="\"$(TARMAN_OS)\"" + rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard ,$d, $2) $(filter $(subst *, %, $2),$d)) SRC=$(call rwildcard, src/common, *.c) SRC+=$(call rwildcard, src/os-specific/$(TARMAN_OS), *.c) diff --git a/include/cli/directives/commands.h b/include/cli/directives/commands.h index a2fe517..337a205 100644 --- a/include/cli/directives/commands.h +++ b/include/cli/directives/commands.h @@ -32,6 +32,7 @@ #define TARMAN_CMD_REMOVE_REPO "remove-repo" #define TARMAN_CMD_LIST_REPOS "list-repos" #define TARMAN_CMD_TEST "test" +#define TARMAN_CMD_VERSION "version" int cli_cmd_help(cli_info_t info); int cli_cmd_install(cli_info_t info); @@ -43,3 +44,4 @@ int cli_cmd_add_repo(cli_info_t info); int cli_cmd_remove_repo(cli_info_t info); int cli_cmd_list_repos(cli_info_t info); int cli_cmd_test(cli_info_t info); +int cli_cmd_version(cli_info_t info); diff --git a/src/common/cli/directives/commands/version.c b/src/common/cli/directives/commands/version.c new file mode 100644 index 0000000..70fd319 --- /dev/null +++ b/src/common/cli/directives/commands/version.c @@ -0,0 +1,58 @@ +/************************************************************************* +| tarman | +| Copyright (C) 2024 Alessandro Salerno | +| | +| This program is free software: you can redistribute it and/or modify | +| it under the terms of the GNU General Public License as published by | +| the Free Software Foundation, either version 3 of the License, or | +| (at your option) any later version. | +| | +| This program is distributed in the hope that it will be useful, | +| but WITHOUT ANY WARRANTY; without even the implied warranty of | +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | +| GNU General Public License for more details. | +| | +| You should have received a copy of the GNU General Public License | +| along with this program. If not, see . | +*************************************************************************/ + +#include +#include +#include + +#include "cli/directives/types.h" +#include "cli/output.h" + +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) + +#ifndef EXT_TARMAN_BUILD +#define EXT_TARMAN_BUILD "unknown" +#endif + +#ifndef EXT_TARMAN_OS +#define EXT_TARMAN_OS "unknown" +#endif + +#ifndef EXT_TARMAN_COMPILER +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +#define EXT_TARMAN_COMPILER \ + "gcc " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) +#elif defined(_clang_version__) +#define EXT_TARMAN_COMPILER "clang " __clang_version__ +#elif defined(__llvm__) +#define EXT_TARMAN_COMPILER "generic llvm" +#else +#define EXT_TARMAN_COMPILER "unknown" +#endif +#endif // EXT_TARMAN_COMPILER + +int cli_cmd_version(cli_info_t info) { + (void)info; + + puts("tarman version " EXT_TARMAN_BUILD); + puts("target: " EXT_TARMAN_OS); + puts("compiled with: " EXT_TARMAN_COMPILER); + + return EXIT_SUCCESS; +} diff --git a/src/common/cli/directives/lookup.c b/src/common/cli/directives/lookup.c index ecfc774..2e296dd 100644 --- a/src/common/cli/directives/lookup.c +++ b/src/common/cli/directives/lookup.c @@ -83,6 +83,13 @@ static cli_drt_desc_t commands[] = { // false, // cli_cmd_list_repos, // "List all local repositories"}, + + {NULL, + TARMAN_CMD_VERSION, + NULL, + false, + cli_cmd_version, + "Show version information"}, }; // {NULL, TARMAN_CMD_TEST, NULL, false, cli_cmd_test, "Test tarman"}};