Allow passing IDs from standard input
This commit is contained in:
+25
-12
@@ -2,8 +2,11 @@ package backend
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -29,6 +32,10 @@ var (
|
||||
FlagShuffle = flag.Bool("shuffle", false, "shuffle the tracklist (to be used with either -play-album or -play-playlist)")
|
||||
FlagVersion = flag.Bool("version", false, "print app version and exit")
|
||||
FlagHelp = flag.Bool("help", false, "print command line options and exit")
|
||||
|
||||
FlagPlayAlbum *bool
|
||||
FlagPlayPlaylist *bool
|
||||
FlagPlayTrack *bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -57,18 +64,24 @@ func init() {
|
||||
return err
|
||||
})
|
||||
|
||||
flag.Func("play-album-by-id", "start playing the given album (ID)", func(s string) error {
|
||||
PlayAlbumCLIArg = s
|
||||
return nil
|
||||
})
|
||||
flag.Func("play-playlist-by-id", "start playing the given playlist (ID)", func(s string) error {
|
||||
PlayPlaylistCLIArg = s
|
||||
return nil
|
||||
})
|
||||
flag.Func("play-track-by-id", "start playing the given track (ID)", func(s string) error {
|
||||
PlayTrackCLIArg = s
|
||||
return nil
|
||||
})
|
||||
if term.IsTerminal(int(os.Stdin.Fd())) {
|
||||
flag.Func("play-album-by-id", "start playing the album with the given ID (can also be passed from standard input)", func(s string) error {
|
||||
PlayAlbumCLIArg = s
|
||||
return nil
|
||||
})
|
||||
flag.Func("play-playlist-by-id", "start playing the playlist with the given ID (can also be passed from standard input)", func(s string) error {
|
||||
PlayPlaylistCLIArg = s
|
||||
return nil
|
||||
})
|
||||
flag.Func("play-track-by-id", "start playing the track with the given ID (can also be passed from standard input)", func(s string) error {
|
||||
PlayTrackCLIArg = s
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
FlagPlayAlbum = flag.Bool("play-album-by-id", false, "")
|
||||
FlagPlayPlaylist = flag.Bool("play-playlist-by-id", false, "")
|
||||
FlagPlayTrack = flag.Bool("play-track-by-id", false, "")
|
||||
}
|
||||
flag.Func("first-track", "start playing from given track (positive integer, to be used with either -play-album or -play-playlist)", func(s string) error {
|
||||
v, err := strconv.Atoi(s)
|
||||
FirstTrackCLIArg = v
|
||||
|
||||
@@ -25,6 +25,7 @@ require (
|
||||
github.com/zalando/go-keyring v0.2.6
|
||||
golang.org/x/net v0.35.0
|
||||
golang.org/x/sys v0.30.0
|
||||
golang.org/x/term v0.29.0
|
||||
golang.org/x/text v0.22.0
|
||||
)
|
||||
|
||||
|
||||
@@ -168,6 +168,8 @@ golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
|
||||
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/dweymouth/supersonic/res"
|
||||
"github.com/dweymouth/supersonic/ui"
|
||||
"github.com/dweymouth/supersonic/ui/util"
|
||||
"golang.org/x/term"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
@@ -31,6 +32,15 @@ func main() {
|
||||
flag.Usage()
|
||||
return
|
||||
}
|
||||
if !term.IsTerminal(int(os.Stdin.Fd())) {
|
||||
if *backend.FlagPlayAlbum {
|
||||
fmt.Scanln(&backend.PlayAlbumCLIArg)
|
||||
} else if *backend.FlagPlayPlaylist {
|
||||
fmt.Scanln(&backend.PlayPlaylistCLIArg)
|
||||
} else if *backend.FlagPlayTrack {
|
||||
fmt.Scanln(&backend.PlayTrackCLIArg)
|
||||
}
|
||||
}
|
||||
// rest of flag actions are handled in backend.StartupApp
|
||||
|
||||
myApp, err := backend.StartupApp(res.AppName, res.DisplayName, res.AppVersion, res.AppVersionTag, res.LatestReleaseURL)
|
||||
|
||||
Reference in New Issue
Block a user