btrfs-progs: Refactor btrfs_add_device() to use btrfs_fs_info
[platform/upstream/btrfs-progs.git] / cmds-property.c
index eed5f4a..9ae1246 100644 (file)
@@ -26,6 +26,7 @@
 #include "props.h"
 #include "ctree.h"
 #include "utils.h"
+#include "help.h"
 
 static const char * const property_cmd_group_usage[] = {
        "btrfs property get/set/list [-t <type>] <object> [<name>] [value]",
@@ -199,12 +200,6 @@ out:
        return ret;
 }
 
-static int print_prop_help(const struct prop_handler *prop)
-{
-       fprintf(stdout, "%-20s%s\n", prop->name, prop->desc);
-       return 0;
-}
-
 static int dump_prop(const struct prop_handler *prop,
                     const char *object,
                     int types,
@@ -217,7 +212,7 @@ static int dump_prop(const struct prop_handler *prop,
                if (!name_and_help)
                        ret = prop->handler(type, object, prop->name, NULL);
                else
-                       ret = print_prop_help(prop);
+                       printf("%-20s%s\n", prop->name, prop->desc);
        }
        return ret;
 }
@@ -298,7 +293,7 @@ static void parse_args(int argc, char **argv,
 {
        int ret;
        char *type_str = NULL;
-       int max_nonopt_args = 0;
+       int max_nonopt_args = 1;
 
        optind = 1;
        while (1) {
@@ -315,8 +310,6 @@ static void parse_args(int argc, char **argv,
                }
        }
 
-       if (object)
-               max_nonopt_args++;
        if (name)
                max_nonopt_args++;
        if (value)
@@ -345,19 +338,13 @@ static void parse_args(int argc, char **argv,
                }
        }
 
-       if (object && optind < argc)
-               *object = argv[optind++];
-       if (name && optind < argc)
+       *object = argv[optind++];
+       if (optind < argc)
                *name = argv[optind++];
-       if (value && optind < argc)
+       if (optind < argc)
                *value = argv[optind++];
 
-       if (optind != argc) {
-               error("unexpected agruments found");
-               usage(usage_str);
-       }
-
-       if (!*types && object && *object) {
+       if (!*types) {
                ret = autodetect_object_types(*object, types);
                if (ret < 0) {
                        error("failed to detect object type: %s",
@@ -393,10 +380,6 @@ static int cmd_property_get(int argc, char **argv)
 
        parse_args(argc, argv, cmd_property_get_usage, &types, &object, &name,
                   NULL, 1);
-       if (!object) {
-               error("invalid arguments");
-               usage(cmd_property_get_usage);
-       }
 
        if (name)
                ret = setget_prop(types, object, name, NULL);
@@ -424,10 +407,6 @@ static int cmd_property_set(int argc, char **argv)
 
        parse_args(argc, argv, cmd_property_set_usage, &types,
                   &object, &name, &value, 3);
-       if (!object || !name || !value) {
-               error("invalid arguments");
-               usage(cmd_property_set_usage);
-       }
 
        ret = setget_prop(types, object, name, value);
 
@@ -450,10 +429,6 @@ static int cmd_property_list(int argc, char **argv)
 
        parse_args(argc, argv, cmd_property_list_usage,
                   &types, &object, NULL, NULL, 1);
-       if (!object) {
-               error("invalid arguments");
-               usage(cmd_property_list_usage);
-       }
 
        ret = dump_props(types, object, 1);