-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.c
57 lines (51 loc) · 1.47 KB
/
cli.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
#ifndef CLP_H
#include "clp.h"
#endif
#define OPTPARSE_IMPLEMENTATION
#include "optparse.h"
// maybe we should make the opts set some flags in an options struct
// and pass it to a func that sets up the lua accordingly
int
main(int argc, char *argv[])
{
struct clp_ctx ctx;
clp_init(&ctx);
struct optparse_long longopts[] = {
{"highlight-line", 'h', OPTPARSE_REQUIRED},
{"override-filetype", 't', OPTPARSE_REQUIRED},
{"list-overrides", 'l', OPTPARSE_NONE},
{"override-colortheme", 's', OPTPARSE_REQUIRED},
{0}};
int option = 0;
char *filename = "";
struct optparse options;
optparse_init(&options, argv);
while ((option = optparse_long(&options, longopts, NULL)) != -1) {
switch (option) {
case 'l':
ctx.program_opts.print_available_overrides = true;
break;
case 't':
ctx.program_opts.filetype_override = options.optarg;
break;
case 'h':
ctx.program_opts.highlight_line = atoi(options.optarg);
break;
case 's':
ctx.program_opts.color_theme_override = options.optarg;
break;
default:
usage();
exit(1);
}
}
filename = optparse_arg(&options);
struct stat buf;
if (!ctx.program_opts.print_available_overrides &&
clp_open_file(&ctx, &buf, filename)) {
return 1;
}
clp_run(&ctx);
clp_cleanup(&ctx);
return 0;
}