|
32 | 32 | #include "shmem.h"
|
33 | 33 | // LUA dependencies
|
34 | 34 | #include "lua/ftl_lua.h"
|
| 35 | +// gravity_parseList() |
| 36 | +#include "gravity-tools.h" |
35 | 37 | // run_dhcp_discover()
|
36 | 38 | #include "tools/dhcp-discover.h"
|
37 | 39 | // run_arp_scan()
|
@@ -126,7 +128,15 @@ static const char __attribute__ ((pure)) *cli_color(const char *color)
|
126 | 128 | return is_term() ? color : "";
|
127 | 129 | }
|
128 | 130 |
|
129 |
| -static inline bool strEndsWith(const char *input, const char *end){ |
| 131 | +// Go back to beginning of line and erase to end of line if STDOUT is a terminal |
| 132 | +const char __attribute__ ((pure)) *cli_over(void) |
| 133 | +{ |
| 134 | + // \x1b[K is the ANSI escape sequence for "erase to end of line" |
| 135 | + return is_term() ? "\r\x1b[K" : "\r"; |
| 136 | +} |
| 137 | + |
| 138 | +static inline bool strEndsWith(const char *input, const char *end) |
| 139 | +{ |
130 | 140 | return strcmp(input + strlen(input) - strlen(end), end) == 0;
|
131 | 141 | }
|
132 | 142 |
|
@@ -165,6 +175,21 @@ void parse_args(int argc, char* argv[])
|
165 | 175 | (argc > 1 && strEndsWith(argv[1], ".db")))
|
166 | 176 | exit(sqlite3_shell_main(argc, argv));
|
167 | 177 |
|
| 178 | + // If the first argument is "gravity" (e.g., /usr/bin/pihole-FTL gravity), |
| 179 | + // we offer some specialized gravity tools |
| 180 | + if(argc > 1 && strcmp(argv[1], "gravity") == 0) |
| 181 | + { |
| 182 | + // pihole-FTL gravity parseList <infile> <outfile> <adlistID> |
| 183 | + if(argc == 6 && strcmp(argv[2], "parseList") == 0) |
| 184 | + { |
| 185 | + // Parse the given list and write the result to the given file |
| 186 | + exit(gravity_parseList(argv[3], argv[4], argv[5])); |
| 187 | + } |
| 188 | + |
| 189 | + printf("Incorrect usage of pihole-FTL gravity subcommand\n"); |
| 190 | + exit(EXIT_FAILURE); |
| 191 | + } |
| 192 | + |
168 | 193 | // DHCP discovery mode
|
169 | 194 | if(argc > 1 && strcmp(argv[1], "dhcp-discover") == 0)
|
170 | 195 | {
|
|
0 commit comments