Line | Branch | Exec | Source |
---|---|---|---|
1 | // SPDX-License-Identifier: LGPL-2.1-or-later | ||
2 | // Copyright (C) 2024 Omar Castro | ||
3 | #include <stdbool.h> | ||
4 | #include <stdlib.h> | ||
5 | #include "app.h" | ||
6 | #include "cmdline.h" | ||
7 | #include "logger.h" | ||
8 | |||
9 | static AuthHandlingMode handling_mode; | ||
10 | static char *cmd_line = NULL; | ||
11 | static char ** cmd_line_argv = NULL; | ||
12 | static int static_argc; | ||
13 | static char ** static_argv; | ||
14 | static bool isInitialized = false; | ||
15 | |||
16 | 33 | const char* app__get_cmd_line(){ | |
17 | 33 | return cmd_line; | |
18 | } | ||
19 | |||
20 | 9 | char** app__get_cmd_line_argv(){ | |
21 | 9 | return cmd_line_argv; | |
22 | } | ||
23 | |||
24 | 51 | AuthHandlingMode app__get_auth_handling_mode(){ | |
25 | 51 | return handling_mode; | |
26 | } | ||
27 | |||
28 | 2 | int app__get_argc(){ | |
29 | 2 | return static_argc; | |
30 | } | ||
31 | 2 | char ** app__get_argv(){ | |
32 | 2 | return static_argv; | |
33 | } | ||
34 | |||
35 | 35 | int app__init(int argc, char *argv[]){ | |
36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | if(isInitialized){ |
37 | ✗ | return 0; | |
38 | } | ||
39 | |||
40 | 35 | static_argc = argc; | |
41 | 35 | static_argv = argv; | |
42 | |||
43 | struct gengetopt_args_info ai; | ||
44 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 34 times.
|
35 | if (cmdline_parser(argc, argv, &ai) != 0) { |
45 | 1 | log__fail_cmdline__print_help(); | |
46 | 1 | goto cmd_exit_1; | |
47 | } | ||
48 | |||
49 | 34 | bool runInSerie = ai.serial_given; | |
50 | 34 | bool runInParallel = ai.parallel_given; | |
51 |
2/4✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
|
34 | bool runInSilence = ai.quiet_given || ai.silent_given; |
52 |
2/4✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
|
34 | bool runInVerbose = !runInSilence && ai.verbose_given; |
53 | |||
54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
|
34 | if(runInSilence){ |
55 | ✗ | log__silence(); | |
56 | } | ||
57 | |||
58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
|
34 | if(runInVerbose){ |
59 | ✗ | log__verbose(); | |
60 | } | ||
61 | |||
62 | |||
63 | |||
64 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
|
34 | if( !ai.command_given ){ |
65 | 1 | log__fail_cmdline__command_required(); | |
66 | 1 | return 1; | |
67 | } | ||
68 | |||
69 | 33 | cmd_line = g_strdup(ai.command_arg); | |
70 | |||
71 | 33 | GError* error = NULL; | |
72 | |||
73 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 32 times.
|
33 | if ( !g_shell_parse_argv ( cmd_line, NULL, &cmd_line_argv, &error ) ){ |
74 | 1 | log__fail_cmdline__error_parsing_command(error->message); | |
75 | 1 | g_error_free ( error ); | |
76 | 1 | goto cmd_exit_1; | |
77 | } | ||
78 | |||
79 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
32 | if(runInSerie && runInParallel){ |
80 | 1 | log__fail_cmdline__either_parallel_or_series(); | |
81 | 1 | goto cmd_exit_1; | |
82 | } | ||
83 | |||
84 |
4/4✓ Branch 0 taken 30 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 29 times.
|
31 | if(!runInSerie && !runInParallel){ |
85 | 1 | log__fail_cmdline__parallel_or_series_required(); | |
86 | 1 | goto cmd_exit_1; | |
87 | } | ||
88 | |||
89 | 30 | handling_mode = runInParallel ? AuthHandlingMode_PARALLEL : AuthHandlingMode_SERIE; | |
90 | |||
91 | 30 | log__verbose__cmd_and_mode(); | |
92 | 30 | cmdline_parser_free(&ai); | |
93 | |||
94 | 30 | return 0; | |
95 | |||
96 | 4 | cmd_exit_1: | |
97 | 4 | cmdline_parser_free(&ai); | |
98 | 4 | return 1; | |
99 | } | ||
100 |