GCC Code Coverage Report


Directory: src/
File: src/client_main.c
Date: 2024-04-25 03:45:42
Exec Total Coverage
Lines: 34 43 79.1%
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 {
18 9214 struct settings settings = {
19 .host = default_host,
20 .port = default_port,
21 };
22 9214 return settings;
23 }
24
25 6 const char *get_usage_string(void)
26 {
27 6 return "[-h|--help] [-V|--version] [-v|--verbose] [-H|--host HOST] [-p|--port PORT] ACTION [ARG...]\n\
28 \n\
29 available actions:\n\
30 \t" CMD_QUEUE_RUN " URL REV - schedule a CI run of repository at URL, revision REV";
31 }
32
33 9214 static int parse_settings(struct settings *settings, int argc, char *argv[])
34 {
35 int opt, longind;
36
37 9214 *settings = default_settings();
38
39 /* clang-format off */
40 static struct option long_options[] = {
41 {"help", no_argument, 0, 'h'},
42 {"version", no_argument, 0, 'V'},
43 {"verbose", no_argument, 0, 'v'},
44 {"host", required_argument, 0, 'H'},
45 {"port", required_argument, 0, 'p'},
46 {0, 0, 0, 0},
47 };
48 /* clang-format on */
49
50
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) {
51
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) {
52 2 case 'h':
53 2 exit_with_usage(0);
54 break;
55 2 case 'V':
56 2 exit_with_version();
57 break;
58 case 'v':
59 g_log_lvl = LOG_LVL_DEBUG;
60 break;
61 9208 case 'H':
62 9208 settings->host = optarg;
63 9208 break;
64 9208 case 'p':
65 9208 settings->port = optarg;
66 9208 break;
67 2 default:
68 2 exit_with_usage(1);
69 break;
70 }
71 }
72
73 9208 return 0;
74 }
75
76 9214 int main(int argc, char *argv[])
77 {
78 struct settings settings;
79 9214 struct client *client = NULL;
80 9214 int ret = 0;
81
82 9214 ret = parse_settings(&settings, argc, argv);
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9208 times.
9208 if (ret < 0)
84 return ret;
85
86 9208 ret = client_create(&client);
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9208 times.
9208 if (ret < 0)
88 return ret;
89
90 9208 ret = client_main(client, &settings, argc - optind, (const char **)argv + optind);
91
1/2
✓ Branch 0 taken 9206 times.
✗ Branch 1 not taken.
9206 if (ret < 0)
92 goto destroy_client;
93
94 9206 destroy_client:
95 9206 client_destroy(client);
96
97 9206 return ret;
98 }
99