From 8e9d752f92e7320f5e36536efe367d26dc00cbdb Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Tue, 19 Feb 2013 21:57:24 +0200 Subject: [PATCH] client: Factor out connect command --- client/commands.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/client/commands.c b/client/commands.c index dd24d10..20a0507 100644 --- a/client/commands.c +++ b/client/commands.c @@ -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 " -- 2.7.4