Skip to content

Commit a2b1538

Browse files
added version command
1 parent c2dfefa commit a2b1538

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ ifeq ($(OS),Windows_NT)
4242
EXEC+=.exe
4343
endif
4444

45+
CFLAGS+=-DEXT_TARMAN_OS="\"$(TARMAN_OS)\""
46+
4547
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard ,$d, $2) $(filter $(subst *, %, $2),$d))
4648
SRC=$(call rwildcard, src/common, *.c)
4749
SRC+=$(call rwildcard, src/os-specific/$(TARMAN_OS), *.c)

include/cli/directives/commands.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define TARMAN_CMD_REMOVE_REPO "remove-repo"
3333
#define TARMAN_CMD_LIST_REPOS "list-repos"
3434
#define TARMAN_CMD_TEST "test"
35+
#define TARMAN_CMD_VERSION "version"
3536

3637
int cli_cmd_help(cli_info_t info);
3738
int cli_cmd_install(cli_info_t info);
@@ -43,3 +44,4 @@ int cli_cmd_add_repo(cli_info_t info);
4344
int cli_cmd_remove_repo(cli_info_t info);
4445
int cli_cmd_list_repos(cli_info_t info);
4546
int cli_cmd_test(cli_info_t info);
47+
int cli_cmd_version(cli_info_t info);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*************************************************************************
2+
| tarman |
3+
| Copyright (C) 2024 Alessandro Salerno |
4+
| |
5+
| This program is free software: you can redistribute it and/or modify |
6+
| it under the terms of the GNU General Public License as published by |
7+
| the Free Software Foundation, either version 3 of the License, or |
8+
| (at your option) any later version. |
9+
| |
10+
| This program is distributed in the hope that it will be useful, |
11+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
12+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13+
| GNU General Public License for more details. |
14+
| |
15+
| You should have received a copy of the GNU General Public License |
16+
| along with this program. If not, see <https://www.gnu.org/licenses/>. |
17+
*************************************************************************/
18+
19+
#include <stdbool.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
23+
#include "cli/directives/types.h"
24+
#include "cli/output.h"
25+
26+
#define STR_HELPER(x) #x
27+
#define STR(x) STR_HELPER(x)
28+
29+
#ifndef EXT_TARMAN_BUILD
30+
#define EXT_TARMAN_BUILD "unknown"
31+
#endif
32+
33+
#ifndef EXT_TARMAN_OS
34+
#define EXT_TARMAN_OS "unknown"
35+
#endif
36+
37+
#ifndef EXT_TARMAN_COMPILER
38+
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
39+
#define EXT_TARMAN_COMPILER \
40+
"gcc " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)
41+
#elif defined(_clang_version__)
42+
#define EXT_TARMAN_COMPILER "clang " __clang_version__
43+
#elif defined(__llvm__)
44+
#define EXT_TARMAN_COMPILER "generic llvm"
45+
#else
46+
#define EXT_TARMAN_COMPILER "unknown"
47+
#endif
48+
#endif // EXT_TARMAN_COMPILER
49+
50+
int cli_cmd_version(cli_info_t info) {
51+
(void)info;
52+
53+
puts("tarman version " EXT_TARMAN_BUILD);
54+
puts("target: " EXT_TARMAN_OS);
55+
puts("compiled with: " EXT_TARMAN_COMPILER);
56+
57+
return EXIT_SUCCESS;
58+
}

src/common/cli/directives/lookup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ static cli_drt_desc_t commands[] = {
8383
// false,
8484
// cli_cmd_list_repos,
8585
// "List all local repositories"},
86+
87+
{NULL,
88+
TARMAN_CMD_VERSION,
89+
NULL,
90+
false,
91+
cli_cmd_version,
92+
"Show version information"},
8693
};
8794
// {NULL, TARMAN_CMD_TEST, NULL, false, cli_cmd_test, "Test tarman"}};
8895

0 commit comments

Comments
 (0)