aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorRob Norris <[email protected]>2024-10-12 03:37:57 +1100
committerGitHub <[email protected]>2024-10-11 09:37:57 -0700
commit7bf525530afdd71af14c9e740a3ed5af3876826a (patch)
tree49508f7ae65554f2b8fa89cc3b56996794d75a8c /cmd
parentb4e4cbeb20240cc7a780fb0e4bebd0134701fee8 (diff)
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. Reviewed-by: Umer Saleem <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #16632
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zfs/zfs_main.c28
-rw-r--r--cmd/zpool/zpool_main.c10
2 files changed, 33 insertions, 5 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c
index f979fd189..97397726c 100644
--- a/cmd/zfs/zfs_main.c
+++ b/cmd/zfs/zfs_main.c
@@ -2162,6 +2162,7 @@ zfs_do_get(int argc, char **argv)
cb.cb_type = ZFS_TYPE_DATASET;
struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
{"json-int", no_argument, NULL, ZFS_OPTION_JSON_NUMS_AS_INT},
{0, 0, 0, 0}
};
@@ -3852,6 +3853,7 @@ zfs_do_list(int argc, char **argv)
nvlist_t *data = NULL;
struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
{"json-int", no_argument, NULL, ZFS_OPTION_JSON_NUMS_AS_INT},
{0, 0, 0, 0}
};
@@ -7436,9 +7438,15 @@ share_mount(int op, int argc, char **argv)
uint_t nthr;
jsobj = data = item = NULL;
+ struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
+ {0, 0, 0, 0}
+ };
+
/* check options */
- while ((c = getopt(argc, argv, op == OP_MOUNT ? ":ajRlvo:Of" : "al"))
- != -1) {
+ while ((c = getopt_long(argc, argv,
+ op == OP_MOUNT ? ":ajRlvo:Of" : "al",
+ op == OP_MOUNT ? long_options : NULL, NULL)) != -1) {
switch (c) {
case 'a':
do_all = 1;
@@ -8374,8 +8382,14 @@ zfs_do_channel_program(int argc, char **argv)
boolean_t sync_flag = B_TRUE, json_output = B_FALSE;
zpool_handle_t *zhp;
+ struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
+ {0, 0, 0, 0}
+ };
+
/* check options */
- while ((c = getopt(argc, argv, "nt:m:j")) != -1) {
+ while ((c = getopt_long(argc, argv, "nt:m:j", long_options,
+ NULL)) != -1) {
switch (c) {
case 't':
case 'm': {
@@ -9083,7 +9097,13 @@ zfs_do_version(int argc, char **argv)
int c;
nvlist_t *jsobj = NULL, *zfs_ver = NULL;
boolean_t json = B_FALSE;
- while ((c = getopt(argc, argv, "j")) != -1) {
+
+ struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
+ {0, 0, 0, 0}
+ };
+
+ while ((c = getopt_long(argc, argv, "j", long_options, NULL)) != -1) {
switch (c) {
case 'j':
json = B_TRUE;
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 09a6c6043..ea180f6b7 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -7340,6 +7340,7 @@ zpool_do_list(int argc, char **argv)
current_prop_type = ZFS_TYPE_POOL;
struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
{"json-int", no_argument, NULL, ZPOOL_OPTION_JSON_NUMS_AS_INT},
{"json-pool-key-guid", no_argument, NULL,
ZPOOL_OPTION_POOL_KEY_GUID},
@@ -10981,6 +10982,7 @@ zpool_do_status(int argc, char **argv)
struct option long_options[] = {
{"power", no_argument, NULL, ZPOOL_OPTION_POWER},
+ {"json", no_argument, NULL, 'j'},
{"json-int", no_argument, NULL, ZPOOL_OPTION_JSON_NUMS_AS_INT},
{"json-flat-vdevs", no_argument, NULL,
ZPOOL_OPTION_JSON_FLAT_VDEVS},
@@ -12589,6 +12591,7 @@ zpool_do_get(int argc, char **argv)
current_prop_type = cb.cb_type;
struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
{"json-int", no_argument, NULL, ZPOOL_OPTION_JSON_NUMS_AS_INT},
{"json-pool-key-guid", no_argument, NULL,
ZPOOL_OPTION_POOL_KEY_GUID},
@@ -13503,7 +13506,12 @@ zpool_do_version(int argc, char **argv)
int c;
nvlist_t *jsobj = NULL, *zfs_ver = NULL;
boolean_t json = B_FALSE;
- while ((c = getopt(argc, argv, "j")) != -1) {
+
+ struct option long_options[] = {
+ {"json", no_argument, NULL, 'j'},
+ };
+
+ while ((c = getopt_long(argc, argv, "j", long_options, NULL)) != -1) {
switch (c) {
case 'j':
json = B_TRUE;