GCC Code Coverage Report


Directory: src/
File: src/client_main.c
Date: 2023-08-28 07:33:56
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@gmail.com>
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 9188 static struct settings default_settings(void)
17 {
18 9188 struct settings settings = {
19 .host = default_host,
20 .port = default_port,
21 };
22 9188 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_RUN " URL REV - schedule a CI run of repository at URL, revision REV";
31 }
32
33 9188 static int parse_settings(struct settings *settings, int argc, char *argv[])
34 {
35 int opt, longind;
36
37 9188 *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 18370 times.
✓ Branch 2 taken 9182 times.
27552 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 9182 times.
✓ Branch 4 taken 9182 times.
✓ Branch 5 taken 2 times.
18370 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 9182 case 'H':
62 9182 settings->host = optarg;
63 9182 break;
64 9182 case 'p':
65 9182 settings->port = optarg;
66 9182 break;
67 2 default:
68 2 exit_with_usage(1);
69 break;
70 }
71 }
72
73 9182 return 0;
74 }
75
76 9188 int main(int argc, char *argv[])
77 {
78 struct settings settings;
79 9188 struct client *client = NULL;
80 9188 int ret = 0;
81
82 9188 ret = parse_settings(&settings, argc, argv);
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9182 times.
9182 if (ret < 0)
84 return ret;
85
86 9182 ret = client_create(&client);
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9182 times.
9182 if (ret < 0)
88 return ret;
89
90 9182 ret = client_main(client, &settings, argc - optind, (const char **)argv + optind);
91
1/2
✓ Branch 0 taken 9180 times.
✗ Branch 1 not taken.
9180 if (ret < 0)
92 goto destroy_client;
93
94 9180 destroy_client:
95 9180 client_destroy(client);
96
97 9180 return ret;
98 }
99