Skip to content

Commit

Permalink
added version command
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro-Salerno committed Nov 10, 2024
1 parent c2dfefa commit a2b1538
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/cli/directives/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
58 changes: 58 additions & 0 deletions src/common/cli/directives/commands/version.c
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>. |
*************************************************************************/

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#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;
}
7 changes: 7 additions & 0 deletions src/common/cli/directives/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"}};

Expand Down

0 comments on commit a2b1538

Please sign in to comment.