-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathag-project.c
57 lines (52 loc) · 1.78 KB
/
ag-project.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "agnostic.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void print_all(struct ag_project* p) {
printf(PROP_COLOR "Name:" TERM_COLOR_RESET " %s\n", p->name);
printf(PROP_COLOR "Root directory:" TERM_COLOR_RESET " %s\n", p->dir);
printf(PROP_COLOR "Project file:" TERM_COLOR_RESET " %s\n", p->file);
if (p->description && p->description[0]) {
printf(PROP_COLOR "Description:" TERM_COLOR_RESET " %s\n", p->description);
}
if (p->bugs) {
printf(PROP_COLOR "Bug tracker:" TERM_COLOR_RESET " %s\n", p->bugs);
}
if (p->docs) {
printf(PROP_COLOR "Documentation:\n" TERM_COLOR_RESET);
for (struct list* l = p->docs; l; l = l->next) {
printf(" - %s\n", (char*) l->data);
}
}
if (p->components) {
printf(PROP_COLOR "Components (%d):\n" TERM_COLOR_RESET, p->component_count);
for (struct list* l = p->components; l; l = l->next) {
struct ag_component* c = (struct ag_component*)l->data;
printf(" - %s\n", c->name);
}
}
}
static void print_directories(struct ag_project* p) {
for (struct list* l = p->components; l; l = l->next) {
struct ag_component* c = (struct ag_component*)l->data;
printf("%s/%s\n", p->dir, c->name);
if (c->alias) {
printf("%s/%s\n", p->dir, c->alias);
}
}
}
void project(int argc, const char** argv) {
struct ag_project* p = ag_load_default_or_die();
if (0 == argc) {
print_all(p);
} else if (1 == argc) {
if (!strcmp("directories", *argv) || !strcmp("dirs", *argv)) {
print_directories(p);
} else {
die("Unknown argument: %s", *argv);
}
} else {
die("Too many arguments");
}
ag_free(p);
}