summaryrefslogtreecommitdiffstats
path: root/src/id128
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-11-15 19:02:55 +0100
committerLennart Poettering <lennart@poettering.net>2019-11-15 19:07:05 +0100
commita19fdd66c2290dbb42e250e04fb0cb24dc749a83 (patch)
treeff30023d8bf55162d996c04860fc3b96398cc712 /src/id128
parentMerge pull request #14037 from poettering/machinectl-pw-agent (diff)
downloadsystemd-a19fdd66c2290dbb42e250e04fb0cb24dc749a83.tar.xz
systemd-a19fdd66c2290dbb42e250e04fb0cb24dc749a83.zip
id128: add new "-u" switch for outputting Ids in UUID format
For some unrelated stuff I wanted the machine ID in UUID format, and it was annoying doing that manually. So let's add a switch for this, so that this works: systemd-id128 machine-id -u
Diffstat (limited to 'src/id128')
-rw-r--r--src/id128/id128.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/id128/id128.c b/src/id128/id128.c
index d3874dbb00..4c5d696c32 100644
--- a/src/id128/id128.c
+++ b/src/id128/id128.c
@@ -7,14 +7,15 @@
#include "id128-print.h"
#include "main-func.h"
#include "pretty-print.h"
+#include "terminal-util.h"
#include "util.h"
#include "verbs.h"
-static bool arg_pretty = false;
-static sd_id128_t arg_app = {};
+static Id128PrettyPrintMode arg_mode = ID128_PRINT_ID128;
+static sd_id128_t arg_app = SD_ID128_NULL;
static int verb_new(int argc, char **argv, void *userdata) {
- return id128_print_new(arg_pretty);
+ return id128_print_new(arg_mode);
}
static int verb_machine_id(int argc, char **argv, void *userdata) {
@@ -29,7 +30,7 @@ static int verb_machine_id(int argc, char **argv, void *userdata) {
return log_error_errno(r, "Failed to get %smachine-ID: %m",
sd_id128_is_null(arg_app) ? "" : "app-specific ");
- return id128_pretty_print(id, arg_pretty);
+ return id128_pretty_print(id, arg_mode);
}
static int verb_boot_id(int argc, char **argv, void *userdata) {
@@ -44,7 +45,7 @@ static int verb_boot_id(int argc, char **argv, void *userdata) {
return log_error_errno(r, "Failed to get %sboot-ID: %m",
sd_id128_is_null(arg_app) ? "" : "app-specific ");
- return id128_pretty_print(id, arg_pretty);
+ return id128_pretty_print(id, arg_mode);
}
static int verb_invocation_id(int argc, char **argv, void *userdata) {
@@ -59,7 +60,7 @@ static int verb_invocation_id(int argc, char **argv, void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to get invocation-ID: %m");
- return id128_pretty_print(id, arg_pretty);
+ return id128_pretty_print(id, arg_mode);
}
static int help(void) {
@@ -70,19 +71,22 @@ static int help(void) {
if (r < 0)
return log_oom();
- printf("%s [OPTIONS...] {COMMAND}\n\n"
- "Generate and print id128 strings.\n\n"
- " -h --help Show this help\n"
- " -p --pretty Generate samples of program code\n"
- " -a --app-specific=ID Generate app-specific IDs\n"
+ printf("%s [OPTIONS...] COMMAND\n\n"
+ "%sGenerate and print 128bit identifiers.%s\n"
"\nCommands:\n"
" new Generate a new id128 string\n"
" machine-id Print the ID of current machine\n"
" boot-id Print the ID of current boot\n"
" invocation-id Print the ID of current invocation\n"
" help Show this help\n"
+ "\nOptions:\n"
+ " -h --help Show this help\n"
+ " -p --pretty Generate samples of program code\n"
+ " -a --app-specific=ID Generate app-specific IDs\n"
+ " -u --uuid Output in UUID format\n"
"\nSee the %s for details.\n"
, program_invocation_short_name
+ , ansi_highlight(), ansi_normal()
, link
);
@@ -103,6 +107,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "version", no_argument, NULL, ARG_VERSION },
{ "pretty", no_argument, NULL, 'p' },
{ "app-specific", required_argument, NULL, 'a' },
+ { "uuid", no_argument, NULL, 'u' },
{},
};
@@ -111,7 +116,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hpa:", options, NULL)) >= 0)
+ while ((c = getopt_long(argc, argv, "hpa:u", options, NULL)) >= 0)
switch (c) {
case 'h':
@@ -121,7 +126,7 @@ static int parse_argv(int argc, char *argv[]) {
return version();
case 'p':
- arg_pretty = true;
+ arg_mode = ID128_PRINT_PRETTY;
break;
case 'a':
@@ -130,6 +135,10 @@ static int parse_argv(int argc, char *argv[]) {
return log_error_errno(r, "Failed to parse \"%s\" as application-ID: %m", optarg);
break;
+ case 'u':
+ arg_mode = ID128_PRINT_UUID;
+ break;
+
case '?':
return -EINVAL;