Skip to content

Commit

Permalink
Merge pull request #4 from doronbehar/MPD_HOST
Browse files Browse the repository at this point in the history
Read $MPD_HOST if -host not provided
  • Loading branch information
natsukagami authored Apr 2, 2019
2 parents 0e0a83a + 65f94a2 commit 50f081f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/mpd-mpris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"flag"
"fmt"
"log"
"os"
"strings"

mpris "github.com/natsukagami/mpd-mpris"
"github.com/natsukagami/mpd-mpris/mpd"
Expand All @@ -18,14 +20,31 @@ var (
)

func init() {
flag.StringVar(&addr, "host", "localhost", "The MPD host.")
flag.StringVar(&addr, "host", "", "The MPD host (default localhost)")
flag.IntVar(&port, "port", 6600, "The MPD port")
flag.StringVar(&password, "pwd", "", "The MPD connection password. Leave empty for none.")
flag.BoolVar(&noInstance, "no-instance", false, "Set the MPDris's interface as 'org.mpris.MediaPlayer2.mpd' instead of 'org.mpris.MediaPlayer2.mpd.instance#'")
}

func main() {
flag.Parse()
if len(addr) == 0 {
env_host := os.Getenv("MPD_HOST")
if len(env_host) == 0 {
addr = "localhost"
} else {
if strings.Index(env_host, "@") > -1 {
addr_pwd := strings.Split(env_host, "@")
// allow providing an alternative password on the command line
if len(password) == 0 {
password = addr_pwd[0]
}
addr = addr_pwd[1]
} else {
addr = env_host
}
}
}

// Attempt to create a MPD connection
var (
Expand Down

0 comments on commit 50f081f

Please sign in to comment.