Skip to content

Commit 0cfe925

Browse files
committed
zpool/zfs: allow --json wherever -j is allowed
Mostly so that with the JSON formatting options are also used, they all look the same. To my eye, `-j --json-flat-vdevs` suggests that they are different or unrelated, while `--json --json-flat-vdevs` invites no further questions. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Signed-off-by: Rob Norris <[email protected]>
1 parent b4e4cbe commit 0cfe925

File tree

9 files changed

+41
-13
lines changed

9 files changed

+41
-13
lines changed

cmd/zfs/zfs_main.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,7 @@ zfs_do_get(int argc, char **argv)
21622162
cb.cb_type = ZFS_TYPE_DATASET;
21632163

21642164
struct option long_options[] = {
2165+
{"json", no_argument, NULL, 'j'},
21652166
{"json-int", no_argument, NULL, ZFS_OPTION_JSON_NUMS_AS_INT},
21662167
{0, 0, 0, 0}
21672168
};
@@ -3852,6 +3853,7 @@ zfs_do_list(int argc, char **argv)
38523853
nvlist_t *data = NULL;
38533854

38543855
struct option long_options[] = {
3856+
{"json", no_argument, NULL, 'j'},
38553857
{"json-int", no_argument, NULL, ZFS_OPTION_JSON_NUMS_AS_INT},
38563858
{0, 0, 0, 0}
38573859
};
@@ -7436,9 +7438,15 @@ share_mount(int op, int argc, char **argv)
74367438
uint_t nthr;
74377439
jsobj = data = item = NULL;
74387440

7441+
struct option long_options[] = {
7442+
{"json", no_argument, NULL, 'j'},
7443+
{0, 0, 0, 0}
7444+
};
7445+
74397446
/* check options */
7440-
while ((c = getopt(argc, argv, op == OP_MOUNT ? ":ajRlvo:Of" : "al"))
7441-
!= -1) {
7447+
while ((c = getopt_long(argc, argv,
7448+
op == OP_MOUNT ? ":ajRlvo:Of" : "al",
7449+
op == OP_MOUNT ? long_options : NULL, NULL)) != -1) {
74427450
switch (c) {
74437451
case 'a':
74447452
do_all = 1;
@@ -8374,8 +8382,14 @@ zfs_do_channel_program(int argc, char **argv)
83748382
boolean_t sync_flag = B_TRUE, json_output = B_FALSE;
83758383
zpool_handle_t *zhp;
83768384

8385+
struct option long_options[] = {
8386+
{"json", no_argument, NULL, 'j'},
8387+
{0, 0, 0, 0}
8388+
};
8389+
83778390
/* check options */
8378-
while ((c = getopt(argc, argv, "nt:m:j")) != -1) {
8391+
while ((c = getopt_long(argc, argv, "nt:m:j", long_options,
8392+
NULL)) != -1) {
83798393
switch (c) {
83808394
case 't':
83818395
case 'm': {
@@ -9083,7 +9097,13 @@ zfs_do_version(int argc, char **argv)
90839097
int c;
90849098
nvlist_t *jsobj = NULL, *zfs_ver = NULL;
90859099
boolean_t json = B_FALSE;
9086-
while ((c = getopt(argc, argv, "j")) != -1) {
9100+
9101+
struct option long_options[] = {
9102+
{"json", no_argument, NULL, 'j'},
9103+
{0, 0, 0, 0}
9104+
};
9105+
9106+
while ((c = getopt_long(argc, argv, "j", long_options, NULL)) != -1) {
90879107
switch (c) {
90889108
case 'j':
90899109
json = B_TRUE;

cmd/zpool/zpool_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7340,6 +7340,7 @@ zpool_do_list(int argc, char **argv)
73407340
current_prop_type = ZFS_TYPE_POOL;
73417341

73427342
struct option long_options[] = {
7343+
{"json", no_argument, NULL, 'j'},
73437344
{"json-int", no_argument, NULL, ZPOOL_OPTION_JSON_NUMS_AS_INT},
73447345
{"json-pool-key-guid", no_argument, NULL,
73457346
ZPOOL_OPTION_POOL_KEY_GUID},
@@ -10981,6 +10982,7 @@ zpool_do_status(int argc, char **argv)
1098110982

1098210983
struct option long_options[] = {
1098310984
{"power", no_argument, NULL, ZPOOL_OPTION_POWER},
10985+
{"json", no_argument, NULL, 'j'},
1098410986
{"json-int", no_argument, NULL, ZPOOL_OPTION_JSON_NUMS_AS_INT},
1098510987
{"json-flat-vdevs", no_argument, NULL,
1098610988
ZPOOL_OPTION_JSON_FLAT_VDEVS},
@@ -12589,6 +12591,7 @@ zpool_do_get(int argc, char **argv)
1258912591
current_prop_type = cb.cb_type;
1259012592

1259112593
struct option long_options[] = {
12594+
{"json", no_argument, NULL, 'j'},
1259212595
{"json-int", no_argument, NULL, ZPOOL_OPTION_JSON_NUMS_AS_INT},
1259312596
{"json-pool-key-guid", no_argument, NULL,
1259412597
ZPOOL_OPTION_POOL_KEY_GUID},
@@ -13503,7 +13506,12 @@ zpool_do_version(int argc, char **argv)
1350313506
int c;
1350413507
nvlist_t *jsobj = NULL, *zfs_ver = NULL;
1350513508
boolean_t json = B_FALSE;
13506-
while ((c = getopt(argc, argv, "j")) != -1) {
13509+
13510+
struct option long_options[] = {
13511+
{"json", no_argument, NULL, 'j'},
13512+
};
13513+
13514+
while ((c = getopt_long(argc, argv, "j", long_options, NULL)) != -1) {
1350713515
switch (c) {
1350813516
case 'j':
1350913517
json = B_TRUE;

man/man8/zfs-list.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The following fields are displayed:
7171
Used for scripting mode.
7272
Do not print headers and separate fields by a single tab instead of arbitrary
7373
white space.
74-
.It Fl j Op Ar --json-int
74+
.It Fl j , -json Op Ar --json-int
7575
Print the output in JSON format.
7676
Specify
7777
.Sy --json-int

man/man8/zfs-mount.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
.Xc
6060
Displays all ZFS file systems currently mounted.
6161
.Bl -tag -width "-j"
62-
.It Fl j
62+
.It Fl j , -json
6363
Displays all mounted file systems in JSON format.
6464
.El
6565
.It Xo

man/man8/zfs-program.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ and any attempts to access or modify other pools will cause an error.
5050
.
5151
.Sh OPTIONS
5252
.Bl -tag -width "-t"
53-
.It Fl j
53+
.It Fl j , -json
5454
Display channel program output in JSON format.
5555
When this flag is specified and standard output is empty -
5656
channel program encountered an error.

man/man8/zfs-set.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ The value
130130
can be used to display all properties that apply to the given dataset's type
131131
.Pq Sy filesystem , volume , snapshot , No or Sy bookmark .
132132
.Bl -tag -width "-s source"
133-
.It Fl j Op Ar --json-int
133+
.It Fl j , -json Op Ar --json-int
134134
Display the output in JSON format.
135135
Specify
136136
.Sy --json-int

man/man8/zpool-get.8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ See the
9898
.Xr zpoolprops 7
9999
manual page for more information on the available pool properties.
100100
.Bl -tag -compact -offset Ds -width "-o field"
101-
.It Fl j Op Ar --json-int, --json-pool-key-guid
101+
.It Fl j , -json Op Ar --json-int, --json-pool-key-guid
102102
Display the list of properties in JSON format.
103103
Specify
104104
.Sy --json-int
@@ -157,7 +157,7 @@ See the
157157
.Xr vdevprops 7
158158
manual page for more information on the available pool properties.
159159
.Bl -tag -compact -offset Ds -width "-o field"
160-
.It Fl j Op Ar --json-int
160+
.It Fl j , -json Op Ar --json-int
161161
Display the list of properties in JSON format.
162162
Specify
163163
.Sy --json-int

man/man8/zpool-list.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ is specified, the command exits after
5959
.Ar count
6060
reports are printed.
6161
.Bl -tag -width Ds
62-
.It Fl j Op Ar --json-int, --json-pool-key-guid
62+
.It Fl j , -json Op Ar --json-int, --json-pool-key-guid
6363
Display the list of pools in JSON format.
6464
Specify
6565
.Sy --json-int

man/man8/zpool-status.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ See the
7070
option of
7171
.Nm zpool Cm iostat
7272
for complete details.
73-
.It Fl j Op Ar --json-int, --json-flat-vdevs, --json-pool-key-guid
73+
.It Fl j , -json Op Ar --json-int, --json-flat-vdevs, --json-pool-key-guid
7474
Display the status for ZFS pools in JSON format.
7575
Specify
7676
.Sy --json-int

0 commit comments

Comments
 (0)