Add version option

This commit is contained in:
Nat 2023-01-20 18:43:52 -08:00
parent c87debfbae
commit 8dd7876ebc
Signed by: nat
GPG Key ID: B53AB05285D710D6
1 changed files with 11 additions and 1 deletions

View File

@ -8,6 +8,8 @@
#include <argp.h>
#include <cmark.h>
static const char *VERSION = "1.0.0-beta.1";
// Structure defining the content and metadata of a single page
struct Page {
char title[80];
@ -220,6 +222,7 @@ char * substitute_string(char dest[], char sub[], char *start, char *end) {
static struct argp_option options[] = {
{ "src", 's', "dir", 0, "Source directory of pages", 0 },
{ "version", 'v', 0, 0, "Print the version", 0 },
{ "template", 't', "file", 0, "Template file path", 0 },
{ "output", 'o', "dir", 0, "Output directory", 0 },
{ 0 }
@ -230,6 +233,9 @@ static char *templateFileName = "./template.html";
static char *outputDirectoryName = "./build";
static int parse_opt(int key, char *arg, struct argp_state *state) {
// Suppress unused parameter warnings
(void) state;
switch (key) {
case 's': {
pagesLocation = arg;
@ -243,6 +249,10 @@ static int parse_opt(int key, char *arg, struct argp_state *state) {
outputDirectoryName = arg;
break;
}
case 'v': {
printf("v%s\n", VERSION);
exit(0);
}
}
return 0;
@ -251,7 +261,7 @@ static int parse_opt(int key, char *arg, struct argp_state *state) {
int main(int argc, char *argv[]) {
int initialInboundCapacity = 2;
struct argp argp = {options, parse_opt, 0, 0 };
struct argp argp = {options, parse_opt, 0, 0, 0, 0, 0 };
argp_parse(&argp, argc, argv, 0, 0, 0);