#include "mkdir.h"
#include "parse-util.h"
#include "pretty-print.h"
-#include "terminal-util.h"
+#include "process-util.h"
#include "reboot-util.h"
#include "string-util.h"
#include "strv.h"
+#include "terminal-util.h"
#include "util.h"
static int help(void) {
log_setup();
- if (strv_contains(strv_skip(argv, 1), "--help"))
+ if (argv_looks_like_help(argc, argv))
return help();
if (argc != 3)
pause();
}
+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
+ */
+
+ 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 const char *const sigchld_code_table[] = {
[CLD_EXITED] = "exited",
bool invoked_as(char *argv[], const char *token);
_noreturn_ void freeze(void);
+
+bool argv_looks_like_help(int argc, char **argv);
#include "path-util.h"
#include "pkcs11-util.h"
#include "pretty-print.h"
+#include "process-util.h"
#include "random-util.h"
#include "string-util.h"
#include "strv.h"
const char *verb;
int r;
- if (argc <= 1)
+ if (argv_looks_like_help(argc, argv))
return help();
if (argc < 3)
#include "log.h"
#include "main-func.h"
#include "memory-util.h"
-#include "path-util.h"
#include "parse-util.h"
+#include "path-util.h"
#include "pretty-print.h"
+#include "process-util.h"
#include "string-util.h"
#include "terminal-util.h"
int r;
char *action, *volume;
- if (argc <= 1 ||
- strv_contains(strv_skip(argv, 1), "--help") ||
- strv_contains(strv_skip(argv, 1), "-h") ||
- streq(argv[1], "help"))
+ if (argv_looks_like_help(argc, argv))
return help();
if (argc < 3)
#include "main-func.h"
#include "path-util.h"
#include "pretty-print.h"
+#include "process-util.h"
#include "string-util.h"
#include "terminal-util.h"
const char *verb;
int r;
- if (argc <= 1 ||
- strv_contains(strv_skip(argv, 1), "--help") ||
- strv_contains(strv_skip(argv, 1), "-h") ||
- streq(argv[1], "help"))
+ if (argv_looks_like_help(argc, argv))
return help();
if (argc < 3)