From 1daa41bde6190671117afa322ced36fcff79bc0d Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 26 Mar 2009 21:50:36 +0100 Subject: [PATCH] allow for setting host and port with command line switches --- doc/ncmpcpp.1 | 6 ++++++ src/helpers.cpp | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 829cefd7..62ce5da8 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -9,6 +9,12 @@ ncmpcpp is an ncurses client for MPD (Music Player Daemon), inspired by ncmpc. Read more about MPD at http://www.musicpd.org .SH "OPTIONS" +.B \-h +Connect to server at host [localhost] +.TP +.B \-?, \-\-help +Connect to server at port [6600] +.TP .B \-?, \-\-help Display help. .TP diff --git a/src/helpers.cpp b/src/helpers.cpp index 0d6016d0..ce5b389a 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -53,7 +53,21 @@ void ParseArgv(int argc, char **argv) for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) + if (strcmp(argv[i], "-h") == 0) + { + if (++i >= argc) + exit(0); + Mpd->SetHostname(argv[i]); + continue; + } + if (strcmp(argv[i], "-p") == 0) + { + if (++i >= argc) + exit(0); + Mpd->SetPort(atoi(argv[i])); + continue; + } + else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { cout << "ncmpcpp version: " << VERSION << endl << "built with support for:" @@ -73,6 +87,8 @@ void ParseArgv(int argc, char **argv) { cout << "Usage: ncmpcpp [OPTION]...\n" + << " -h connect to server at host [localhost]\n" + << " -p connect to server at port [6600]\n" << " -?, --help show this help message\n" << " -v, --version display version information\n\n" << " play start playing\n"