mirror of
https://github.com/xHyroM/gimi.git
synced 2024-11-10 02:38:06 +01:00
feat: ci generation
This commit is contained in:
parent
31c457851a
commit
c199fde849
5 changed files with 89 additions and 2 deletions
14
.builds/alpine.yml
Normal file
14
.builds/alpine.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
image: alpine/latest
|
||||
packages:
|
||||
- git
|
||||
sources:
|
||||
- "https://git.sr.ht/~hyro/gimi"
|
||||
secrets:
|
||||
- 55691174-b52f-477c-81ea-dd32deff19b8now
|
||||
tasks:
|
||||
- sync: |
|
||||
set +x
|
||||
git remote add gimi-github git@github.com:xhyrom/gimi.git
|
||||
git push -f --all gimi-github
|
||||
git push -f --tags gimi-github
|
||||
set -x
|
|
@ -1,4 +1,5 @@
|
|||
#include "../gimi_constants.h"
|
||||
#include "command/ci.h"
|
||||
#include "command/config.h"
|
||||
#include "command/init.h"
|
||||
#include "command/provider.h"
|
||||
|
@ -20,14 +21,18 @@ void cli_print_version() {
|
|||
int cli_handle(int argc, char **argv) {
|
||||
char *sub_command = argv[0];
|
||||
|
||||
if (strcmp(sub_command, "init") == 0) {
|
||||
return cli_command_init(argc, argv);
|
||||
if (strcmp(sub_command, "ci") == 0) {
|
||||
return cli_command_ci(argc, argv);
|
||||
}
|
||||
|
||||
if (strcmp(sub_command, "config") == 0) {
|
||||
return cli_command_config(argc, argv);
|
||||
}
|
||||
|
||||
if (strcmp(sub_command, "init") == 0) {
|
||||
return cli_command_init(argc, argv);
|
||||
}
|
||||
|
||||
if (strcmp(sub_command, "provider") == 0) {
|
||||
return cli_command_provider(argc, argv);
|
||||
}
|
||||
|
|
66
src/cli/command/ci.c
Normal file
66
src/cli/command/ci.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "../../config.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SOURCEHUT \
|
||||
"image: alpine/latest\n" \
|
||||
"packages:\n" \
|
||||
" - git\n" \
|
||||
"sources:\n" \
|
||||
" - %s\n" \
|
||||
"secrets:\n" \
|
||||
" - <add>\n" \
|
||||
"tasks:\n" \
|
||||
" - sync: |\n" \
|
||||
" %s\n" \
|
||||
" %s\n" \
|
||||
" %s\n"
|
||||
|
||||
int generate(int argc, char **argv) {
|
||||
struct gimi_config *cfg = config_read();
|
||||
struct gimi_config_provider *provider;
|
||||
|
||||
if (argc == 2) {
|
||||
provider = config_find_provider(cfg, argv[1]);
|
||||
|
||||
if (provider == NULL) {
|
||||
printf("error: no such provider '%s'", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < cfg->providers_size; i++) {
|
||||
if (cfg->providers[i]->primary) {
|
||||
provider = cfg->providers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (provider == NULL) {
|
||||
printf("error: can't find primary provider");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
config_free(cfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cli_command_ci(int argc, char **argv) {
|
||||
if (argc == 1) {
|
||||
printf("usage: gimi ci generate [provider]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// remove "ci" from args
|
||||
argc -= 1;
|
||||
argv += 1;
|
||||
|
||||
char *subcommand = argv[0];
|
||||
|
||||
if (strcmp(subcommand, "generate") == 0) {
|
||||
return generate(argc, argv);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
1
src/cli/command/ci.h
Normal file
1
src/cli/command/ci.h
Normal file
|
@ -0,0 +1 @@
|
|||
int cli_command_ci(int argc, char **argv);
|
|
@ -74,6 +74,7 @@ struct gimi_config_provider *config_find_provider(struct gimi_config *cfg,
|
|||
for (int i = 0; i < cfg->providers_size; i++) {
|
||||
if (strcmp(cfg->providers[i]->name, name) == 0) {
|
||||
provider = cfg->providers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue