GCC Code Coverage Report


Directory: src/
File: src/client_main.c
Date: 2026-09-16 18:00:49
Exec Total Coverage
Lines: 34 43 79.1%
Functions: 4 4 100.0%
Branches: 10 14 71.4%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2022 Egor Tensin <egor@tensin.name>
3 * This file is part of the "cimple" project.
4 * For details, see https://github.com/egor-tensin/cimple.
5 * Distributed under the MIT License.
6 */
7
8 #include "client.h"
9 #include "cmd_line.h"
10 #include "const.h"
11 #include "log.h"
12
13 #include <getopt.h>
14 #include <unistd.h>
15
16 9214 static struct settings default_settings(void) {
17 9214 struct settings settings = {
18 .host = default_host,
19 .port = default_port,
20 };
21 9214 return settings;
22 }
23
24 6 const char* get_usage_string(void) {
25 6 return "[-h|--help] [-V|--version] [-v|--verbose] [-H|--host HOST] [-p|--port PORT] ACTION [ARG...]\n\
26 \n\
27 available actions:\n\
28 \t" CMD_QUEUE_RUN " URL REV - schedule a CI run of repository at URL, revision REV";
29 }
30
31 9214 static int parse_settings(struct settings* settings, int argc, char* argv[]) {
32 int opt, longind;
33
34 9214 *settings = default_settings();
35
36 static struct option long_options[] = {
37 {"help", no_argument, 0, 'h'},
38 {"version", no_argument, 0, 'V'},
39 {"verbose", no_argument, 0, 'v'},
40 {"host", required_argument, 0, 'H'},
41 {"port", required_argument, 0, 'p'},
42 {0, 0, 0, 0},
43 };
44
45
2/2
✓ Branch 1 taken 18422 times.
✓ Branch 2 taken 9208 times.
27630 while ((opt = getopt_long(argc, argv, "hVvH:p:", long_options, &longind)) != -1) {
46
5/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9208 times.
✓ Branch 4 taken 9208 times.
✓ Branch 5 taken 2 times.
18422 switch (opt) {
47 2 case 'h':
48 2 exit_with_usage(0);
49 break;
50 2 case 'V':
51 2 exit_with_version();
52 break;
53 case 'v':
54 g_log_lvl = LOG_LVL_DEBUG;
55 break;
56 9208 case 'H':
57 9208 settings->host = optarg;
58 9208 break;
59 9208 case 'p':
60 9208 settings->port = optarg;
61 9208 break;
62 2 default:
63 2 exit_with_usage(1);
64 break;
65 }
66 }
67
68 9208 return 0;
69 }
70
71 9214 int main(int argc, char* argv[]) {
72 struct settings settings;
73 9214 struct client* client = NULL;
74 9214 int ret = 0;
75
76 9214 ret = parse_settings(&settings, argc, argv);
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9208 times.
9208 if (ret < 0)
78 return ret;
79
80 9208 ret = client_create(&client);
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9208 times.
9208 if (ret < 0)
82 return ret;
83
84 9208 ret = client_main(client, &settings, argc - optind, (const char**)argv + optind);
85
1/2
✓ Branch 0 taken 9206 times.
✗ Branch 1 not taken.
9206 if (ret < 0)
86 goto destroy_client;
87
88 9206 destroy_client:
89 9206 client_destroy(client);
90
91 9206 return ret;
92 }
93