Skip to content

Commit b5c02e2

Browse files
authored
Report fetchfetch's own version (#13)
This both reports this tool's own version when getting run, and also adds basic CLI options so that the `--version` option could be added.
2 parents 1a11884 + ae3509d commit b5c02e2

File tree

8 files changed

+141
-15
lines changed

8 files changed

+141
-15
lines changed

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
fetchfetch: art.o stats.o fetchfetch.c
2-
$(CC) -o fetchfetch art.o stats.o fetchfetch.c
1+
fetchfetch: art.o args.o stats.o version.o fetchfetch.c
2+
$(CC) -o fetchfetch art.o args.o stats.o version.o fetchfetch.c
3+
4+
args.o: args.c args.h
5+
$(CC) -c -o args.o args.c
36

47
art.o: art.c art.h
58
$(CC) -c -o art.o art.c
69

7-
stats.o: stats.c stats.h
10+
stats.o: stats.c stats.h version.c version.h
811
$(CC) -c -o stats.o stats.c
912

13+
version.o: version.c version.h
14+
$(CC) -c -o version.o version.c
15+
1016
.PHONY: run
1117
run: fetchfetch
1218
./fetchfetch

args.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* fetchfetch - Fetch the stats of your *fetch tools
3+
* Copyright (C) 2025 Spenser Black
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+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
#include <stdbool.h>
17+
#include <string.h>
18+
#include "args.h"
19+
20+
bool print_help = false;
21+
bool print_version = false;
22+
23+
void parse_args(int argc, char **argv) {
24+
for (int i = 1; i < argc; i++) {
25+
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
26+
print_help = true;
27+
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
28+
print_version = true;
29+
}
30+
}
31+
}
32+
33+
const char *help_message = "Usage: fetchfetch [OPTIONS...]\n"
34+
"Fetch the stats of your *fetch tools\n"
35+
"\n"
36+
"Options:\n"
37+
" -h, --help Print this message and exit\n"
38+
" -v, --version Print the version and exit\n";

args.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* fetchfetch - Fetch the stats of your *fetch tools
3+
* Copyright (C) 2025 Spenser Black
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+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
#ifndef FETCH_FETCH_ARGS_H
17+
#define FETCH_FETCH_ARGS_H
18+
#include <stdbool.h>
19+
20+
extern bool print_help;
21+
extern bool print_version;
22+
extern const char *help_message;
23+
24+
void parse_args(int argc, char **argv);
25+
26+
#endif

fetchfetch.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@
1414
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1515
*/
1616
#include <stdio.h>
17+
#include "args.h"
1718
#include "art.h"
1819
#include "stats.h"
20+
#include "version.h"
1921

2022
int main(int argc, char *argv[]) {
21-
const FetchStat *stats = get_stats();
23+
FetchStat *stats;
24+
parse_args(argc, argv);
25+
26+
if (print_help) {
27+
printf("%s", help_message);
28+
return 0;
29+
}
30+
if (print_version) {
31+
printf("fetchfetch %s\n", version);
32+
return 0;
33+
}
34+
35+
stats = get_stats();
2236
for (int line_index = 0; line_index < ART_HEIGHT || line_index < STATS_SIZE; line_index++) {
2337
if (line_index < ART_HEIGHT) {
2438
for (int col_index = 0; col_index < ART_WIDTH; col_index++) {

stats.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string.h>
1919
#include <stdbool.h>
2020
#include "stats.h"
21+
#include "version.h"
2122

2223
char *app_version_fallback = "Not installed";
2324

@@ -113,13 +114,15 @@ FetchStat* get_stats() {
113114
FetchStat *stats = malloc(STATS_SIZE * sizeof(FetchStat));
114115
stats[0].label = "Fastfetch";
115116
stats[0].version = fastfetch();
116-
stats[1].label = "Neofetch";
117-
stats[1].version = neofetch();
118-
stats[2].label = "onefetch";
119-
stats[2].version = onefetch();
120-
stats[3].label = "pfetch";
121-
stats[3].version = pfetch();
122-
stats[4].label = "UwUfetch";
123-
stats[4].version = uwufetch();
117+
stats[1].label = "fetchfetch";
118+
stats[1].version = version;
119+
stats[2].label = "Neofetch";
120+
stats[2].version = neofetch();
121+
stats[3].label = "onefetch";
122+
stats[3].version = onefetch();
123+
stats[4].label = "pfetch";
124+
stats[4].version = pfetch();
125+
stats[5].label = "UwUfetch";
126+
stats[5].version = uwufetch();
124127
return stats;
125128
}

stats.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#define FETCH_FETCH_STATS_H
1818

1919
typedef struct {
20-
char *label;
21-
char *version;
20+
const char *label;
21+
const char *version;
2222
} FetchStat;
2323

2424
/**
@@ -46,7 +46,7 @@ char* pfetch();
4646
*/
4747
char* uwufetch();
4848

49-
#define STATS_SIZE 5
49+
#define STATS_SIZE 6
5050
/**
5151
* Gets all stats.
5252
*/

version.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* fetchfetch - Fetch the stats of your *fetch tools
3+
* Copyright (C) 2025 Spenser Black
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+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
#include "version.h"
17+
18+
const char* version = "1.0.1";

version.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* fetchfetch - Fetch the stats of your *fetch tools
3+
* Copyright (C) 2025 Spenser Black
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+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
#ifndef FETCH_FETCH_VERSION_H
17+
#define FETCH_FETCH_VERSION_H
18+
19+
extern const char *version;
20+
21+
#endif

0 commit comments

Comments
 (0)