feat: add simple getopt cli
This commit is contained in:
parent
de71b99539
commit
94a4ac27c5
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,4 @@
|
||||
out/
|
||||
examples/
|
||||
compile_commands.json
|
||||
.cache/
|
||||
|
2
Makefile
2
Makefile
@ -11,6 +11,8 @@ OBJ = $(SRC:.c=.o)
|
||||
OUTDIR := out/
|
||||
OBJDIR := out/obj
|
||||
BINDIR := out/bin
|
||||
CFLAGS += -DSCI_VERSION="\"$(VERSION)\"" -DSCI_NAME="\"$(NAME)\""
|
||||
CFLAGS += -Wall -Werror
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
|
11
README.md
11
README.md
@ -1,4 +1,4 @@
|
||||
# Suckless Continous Integration
|
||||
# Suckless/Simple Continous Integration
|
||||
Jenkins, Travis, GitHub Actions, GitLab CI. The list goes on.
|
||||
This is a minimal tool for fulfilling the CI (Continous Integration) use case.
|
||||
|
||||
@ -70,3 +70,12 @@ What language should I implement `scid` in?
|
||||
- `java` slow devtime, bloated. No.
|
||||
- `rust` slow devtime (not familiar), great tooling, too many risks for a first prototype. No.
|
||||
- `shell` quick, easy, instant spaghetti. No.
|
||||
|
||||
I choose `c`!
|
||||
|
||||
I also choose `Makefile`s! - Just to force myself to use another build system than CMake!
|
||||
If you want `compile_commands.json` files, you should use [bear](https://github.com/rizsotto/Bear) as it works well
|
||||
|
||||
### Progress
|
||||
- [ ] Zeroth things first, let's create a simple CLI application with `--verbosity VAL` and `--help` options.
|
||||
- [ ] First things first, let's implement something that reacts when some provided file changes.
|
||||
|
61
src/main.c
61
src/main.c
@ -1,5 +1,64 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <getopt.h>
|
||||
|
||||
struct cli_options {
|
||||
int verbosity;
|
||||
bool help;
|
||||
bool version;
|
||||
};
|
||||
|
||||
struct cli_options new_options() {
|
||||
struct cli_options result;
|
||||
result.verbosity = 0;
|
||||
result.help = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
// <max
|
||||
char* help_msg =
|
||||
"Usage: %s [-v level] [-h] [-V]\n"
|
||||
"\n"
|
||||
SCI_NAME " is a simple contiuous integration system.\n"
|
||||
"\n"
|
||||
"OPTIONS:\n"
|
||||
" -v level Set verbosity level [0-3]\n"
|
||||
" -h Show this message and exit\n"
|
||||
" -V Show version and exit\n"
|
||||
;
|
||||
// <max
|
||||
|
||||
void print_help(FILE * out, char* prog_name) {
|
||||
fprintf(out, help_msg, prog_name);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("Hello, World!\n");
|
||||
struct cli_options options = new_options();
|
||||
int opt;
|
||||
while((opt = getopt(argc, argv, "v:hV")) != -1) {
|
||||
switch(opt) {
|
||||
case 'v':
|
||||
options.verbosity = atoi(optarg);
|
||||
break;
|
||||
case 'V':
|
||||
options.version = true;
|
||||
break;
|
||||
case 'h':
|
||||
options.help = true;
|
||||
break;
|
||||
default: // '?'
|
||||
print_help(stderr, argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if(options.help) {
|
||||
print_help(stdout, argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
if(options.version) {
|
||||
fprintf(stdout, SCI_VERSION "\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user