basic/argv-util: drop unused code
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
int saved_argc = 0;
|
||||
char **saved_argv = NULL;
|
||||
@@ -69,32 +68,6 @@ bool invoked_by_systemd(void) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
bool argv_looks_like_help(int argc, char **argv) {
|
||||
char **l;
|
||||
|
||||
/* Scans the command line for indications the user asks for help. This is supposed to be called by
|
||||
* tools that do not implement getopt()-style command line parsing because they are not primarily
|
||||
* user-facing. Detects four ways of asking for help:
|
||||
*
|
||||
* 1. Passing zero arguments
|
||||
* 2. Passing "help" as first argument
|
||||
* 3. Passing --help as any argument
|
||||
* 4. Passing -h as any argument
|
||||
*/
|
||||
assert(argc == 0 || argv);
|
||||
|
||||
if (argc <= 1)
|
||||
return true;
|
||||
|
||||
if (streq_ptr(argv[1], "help"))
|
||||
return true;
|
||||
|
||||
l = strv_skip(argv, 1);
|
||||
|
||||
return strv_contains(l, "--help") ||
|
||||
strv_contains(l, "-h");
|
||||
}
|
||||
|
||||
static int update_argv(const char name[], size_t l) {
|
||||
static int can_do = -1;
|
||||
int r;
|
||||
|
||||
@@ -10,7 +10,6 @@ void save_argc_argv(int argc, char **argv);
|
||||
|
||||
bool invoked_as(char *argv[], const char *token);
|
||||
bool invoked_by_systemd(void) _const_;
|
||||
bool argv_looks_like_help(int argc, char **argv);
|
||||
|
||||
int rename_process_full(const char *comm, const char *invocation);
|
||||
static inline int rename_process(const char *name) {
|
||||
|
||||
@@ -99,19 +99,6 @@ TEST(rename_process) {
|
||||
test_rename_process_one("1234567", 1); /* should always fit */
|
||||
}
|
||||
|
||||
TEST(argv_help) {
|
||||
assert_se(argv_looks_like_help(1, STRV_MAKE("program")));
|
||||
assert_se(argv_looks_like_help(2, STRV_MAKE("program", "help")));
|
||||
assert_se(argv_looks_like_help(3, STRV_MAKE("program", "arg1", "--help")));
|
||||
assert_se(argv_looks_like_help(4, STRV_MAKE("program", "arg1", "arg2", "-h")));
|
||||
assert_se(!argv_looks_like_help(2, STRV_MAKE("program", "arg1")));
|
||||
assert_se(!argv_looks_like_help(4, STRV_MAKE("program", "arg1", "arg2", "--h")));
|
||||
assert_se(!argv_looks_like_help(3, STRV_MAKE("program", "Help", "arg2")));
|
||||
assert_se(argv_looks_like_help(5, STRV_MAKE("program", "--help", "arg1", "-h", "--help")));
|
||||
assert_se(!argv_looks_like_help(4, STRV_MAKE("program","arg1", "arg2", "-H")));
|
||||
assert_se(!argv_looks_like_help(3, STRV_MAKE("program", "--Help", "arg2")));
|
||||
}
|
||||
|
||||
static int intro(void) {
|
||||
log_show_color(true);
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user