client: Factor out connect command
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 19 Feb 2013 19:57:24 +0000 (21:57 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 21 Feb 2013 14:23:01 +0000 (16:23 +0200)
client/commands.c

index dd24d10..20a0507 100644 (file)
@@ -207,7 +207,19 @@ static int cmd_scan(char *args[], int num, struct option *options)
 
 static int cmd_connect(char *args[], int num, struct option *options)
 {
-       return -1;
+       int err;
+
+       if (num > 2)
+               return -E2BIG;
+
+       if (num < 2)
+               return -EINVAL;
+
+       err = connect_service(connection, args[1]);
+       if (err == 0)
+               printf("Connected\n");
+
+       return 0;
 }
 
 static int cmd_disconnect(char *args[], int num, struct option *options)
@@ -504,17 +516,6 @@ int commands_no_options(DBusConnection *connection, char *argv[], int argc)
                cmd_help(NULL, 0, NULL);
                printf("\nNote: arguments and output are considered "
                                "EXPERIMENTAL for now.\n\n");
-       } else if (strcmp(argv[0], "connect") == 0) {
-               if (argc != 2) {
-                       fprintf(stderr, "Connect requires a service name or "
-                                                       "path, see help\n");
-                       error = -EINVAL;
-               } else
-                       error = connect_service(connection,
-                                               strip_service_path(argv[1]));
-               if (error == 0)
-                       printf("Connected to: %s\n",
-                                               strip_service_path(argv[1]));
        } else if (strcmp(argv[0], "disconnect") == 0) {
                if (argc != 2) {
                        fprintf(stderr, "Disconnect requires a service name or "