diff --git a/man/systemd-mount.xml b/man/systemd-mount.xml
index 558fd03fc14..05357b06b13 100644
--- a/man/systemd-mount.xml
+++ b/man/systemd-mount.xml
@@ -121,6 +121,7 @@
+
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c
index a0ca17f0f07..f127168c602 100644
--- a/src/mount/mount-tool.c
+++ b/src/mount/mount-tool.c
@@ -74,6 +74,7 @@ static gid_t arg_gid = GID_INVALID;
static bool arg_fsck = true;
static bool arg_aggressive_gc = false;
static bool arg_tmpfs = false;
+static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
STATIC_DESTRUCTOR_REGISTER(arg_mount_what, freep);
STATIC_DESTRUCTOR_REGISTER(arg_mount_where, freep);
@@ -128,6 +129,7 @@ static int help(void) {
" -l --full Do not ellipsize output\n"
" --no-ask-password Do not prompt for password\n"
" -q --quiet Suppress information messages during runtime\n"
+ " --json=pretty|short|off Generate JSON output\n"
" --user Run as user unit\n"
" -H --host=[USER@]HOST Operate on remote host\n"
" -M --machine=CONTAINER Operate on local container\n"
@@ -176,6 +178,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_AUTOMOUNT_PROPERTY,
ARG_BIND_DEVICE,
ARG_LIST,
+ ARG_JSON,
};
static const struct option options[] = {
@@ -207,6 +210,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "unmount", no_argument, NULL, 'u' }, /* Compat spelling */
{ "collect", no_argument, NULL, 'G' },
{ "tmpfs", no_argument, NULL, 'T' },
+ { "json", required_argument, NULL, ARG_JSON },
{},
};
@@ -361,6 +365,13 @@ static int parse_argv(int argc, char *argv[]) {
arg_tmpfs = true;
break;
+ case ARG_JSON:
+ r = parse_json_argument(optarg, &arg_json_format_flags);
+ if (r <= 0)
+ return r;
+
+ break;
+
case '?':
return -EINVAL;
@@ -1435,7 +1446,6 @@ static int list_devices(void) {
if (r < 0)
return log_error_errno(r, "Failed to set sort index: %m");
- table_set_header(table, arg_legend);
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
FOREACH_DEVICE(e, d) {
@@ -1479,13 +1489,7 @@ static int list_devices(void) {
}
}
- pager_open(arg_pager_flags);
-
- r = table_print(table, NULL);
- if (r < 0)
- return table_log_print_error(r);
-
- return 0;
+ return table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
}
static int run(int argc, char* argv[]) {
diff --git a/test/units/TEST-74-AUX-UTILS.mount.sh b/test/units/TEST-74-AUX-UTILS.mount.sh
index 14253c358d1..d440a7c667d 100755
--- a/test/units/TEST-74-AUX-UTILS.mount.sh
+++ b/test/units/TEST-74-AUX-UTILS.mount.sh
@@ -23,6 +23,7 @@ systemd-mount --list --full
systemd-mount --list --no-legend
systemd-mount --list --no-pager
systemd-mount --list --quiet
+systemd-mount --list --json=pretty
# tmpfs
mkdir -p "$WORK_DIR/mnt/foo/bar"