update usage

This commit is contained in:
2025-09-07 17:56:39 -04:00
parent 73350ba0fc
commit 62d8f3aace

View File

@@ -29,7 +29,7 @@
static void usage(int status) static void usage(int status)
{ {
if (status != 0) { if (status != 0) {
puts("Try 'yait --help' for more information.\n"); puts("Try 'yait --help' for more information.");
return; return;
} }
@@ -42,9 +42,15 @@ static void usage(int status)
print_option("--lib", "Make this a library"); print_option("--lib", "Make this a library");
print_option("-l <licence>", print_option("-l <licence>",
"Set licence. This list can be found by passing 'list'"); "Set licence. This list can be found by passing 'list'");
print_option("-E", "Open editor after project creation"); print_option("-E", "Open $EDITOR after project creation");
puts(" --help display this help text and exit\n"); print_option("--autotools", "Use the autotools build system");
puts(" --version output version information and exit\n"); print_option("--cmake", "Use the cmake build system");
print_option("--make", "Use the GNU make build system (default)");
print_option("--bare", "Minimal C project structure");
print_option("--flat", "All files in project root.");
print_option("--extras=<arg1>,<arg2>", "Extra build options, Pass list to list out options.");
puts(" --help display this help text and exit");
puts(" --version output version information and exit");
} }
void print_lines(const char *first, ...) void print_lines(const char *first, ...)
@@ -156,8 +162,7 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
} }
if (optind >= argc) { if (optind >= argc) {
fputs("error: missing project name\n", stderr); return HELP_REQUESTED;
return 1;
} }
conf->project = str_dup(argv[optind]); conf->project = str_dup(argv[optind]);
@@ -166,34 +171,33 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
int get_name(char **output) int get_name(char **output)
{ {
FILE *pipe; FILE *fp;
char buffer[128]; char buf[256];
size_t output_len = 0; char *res = NULL;
struct passwd *pw;
*output = NULL; fp = popen("git config --get user.name", "r");
if (fp) {
pipe = popen("git config user.name", "r"); if (fgets(buf, sizeof buf, fp)) {
if (!pipe) size_t len = strlen(buf);
exit(EXIT_FAILURE); if (len > 0 && buf[len - 1] == '\n')
buf[len - 1] = '\0';
while (fgets(buffer, sizeof(buffer), pipe) != NULL) { res = strdup(buf);
size_t chunk_len = strlen(buffer);
char *new_output = realloc(*output, output_len + chunk_len + 1);
if (!new_output) {
pclose(pipe);
exit(EXIT_FAILURE);
} }
*output = new_output; pclose(fp);
memcpy((*output) + output_len, buffer, chunk_len);
output_len += chunk_len;
(*output)[output_len] = '\0';
} }
pclose(pipe); if (!res) {
pw = getpwuid(getuid());
if (!pw || !pw->pw_name)
return -1;
res = strdup(pw->pw_name);
}
if (output_len > 0 && (*output)[output_len - 1] == '\n') if (!res)
(*output)[output_len - 1] = '\0'; return -1;
*output = res;
return 0; return 0;
} }
@@ -224,6 +228,10 @@ int main(int argc, char **argv)
EXIT_FAILURE; EXIT_FAILURE;
status = parse_arguments(&manifest, argc, argv); status = parse_arguments(&manifest, argc, argv);
if (status == HELP_REQUESTED) {
usage(0);
}
if (status) { if (status) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }