This commit is contained in:
abs3nt 2023-01-13 22:27:38 -08:00
parent 1c7249cbca
commit 060532015c
32 changed files with 54 additions and 51 deletions

View File

@ -1,6 +1,8 @@
package main package main
import "gospt/cmd" import (
"gospt/src/cmd"
)
func main() { func main() {
defCmd := "tui" defCmd := "tui"

View File

@ -10,8 +10,8 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"gospt/internal/config" "gospt/src/config"
"gospt/internal/gctx" "gospt/src/gctx"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
spotifyauth "github.com/zmb3/spotify/v2/auth" spotifyauth "github.com/zmb3/spotify/v2/auth"

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -8,9 +8,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"gospt/internal/auth" "gospt/src/auth"
"gospt/internal/config" "gospt/src/config"
"gospt/internal/gctx" "gospt/src/gctx"
"github.com/cristalhq/aconfig" "github.com/cristalhq/aconfig"
"github.com/cristalhq/aconfig/aconfigyaml" "github.com/cristalhq/aconfig/aconfigyaml"
@ -45,26 +45,27 @@ func Execute(defCmd string) {
} }
func init() { func init() {
configDir, _ := os.UserConfigDir()
cfgFile = filepath.Join(configDir, "gospt/client.yml")
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
if !(len(os.Args) > 1) || os.Args[1] != "completion" { cobra.OnInitialize(initClient)
initConfig() }
var err error
ctx = gctx.NewContext(context.Background()) func initClient() {
client, err = auth.GetClient(ctx) var err error
if err != nil { ctx = gctx.NewContext(context.Background())
panic(err) client, err = auth.GetClient(ctx)
} if err != nil {
currentUser, err := client.CurrentUser(ctx) panic(err)
if err != nil {
panic(err)
}
ctx.UserId = currentUser.ID
} }
currentUser, err := client.CurrentUser(ctx)
if err != nil {
panic(err)
}
ctx.UserId = currentUser.ID
} }
func initConfig() { func initConfig() {
configDir, _ := os.UserConfigDir()
cfgFile = filepath.Join(configDir, "gospt/client.yml")
yamlDecoder := aconfigyaml.New() yamlDecoder := aconfigyaml.New()
loader := aconfig.LoaderFor(&config.Values, aconfig.Config{ loader := aconfig.LoaderFor(&config.Values, aconfig.Config{

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/tui" "gospt/src/tui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -4,8 +4,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"gospt/internal/commands" "gospt/src/commands"
"gospt/internal/tui" "gospt/src/tui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -4,8 +4,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"gospt/internal/commands" "gospt/src/commands"
"gospt/internal/tui" "gospt/src/tui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"gospt/internal/commands" "gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -11,7 +11,7 @@ import (
"strings" "strings"
"time" "time"
"gospt/internal/gctx" "gospt/src/gctx"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
) )

View File

@ -3,8 +3,8 @@ package tui
import ( import (
"fmt" "fmt"
"gospt/internal/commands" "gospt/src/commands"
"gospt/internal/gctx" "gospt/src/gctx"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"time" "time"
"gospt/internal/commands" "gospt/src/commands"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"time" "time"
"gospt/internal/gctx" "gospt/src/gctx"
"github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"

View File

@ -3,7 +3,7 @@ package tui
import ( import (
"fmt" "fmt"
"gospt/internal/gctx" "gospt/src/gctx"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"

View File

@ -5,8 +5,8 @@ import (
"sync" "sync"
"time" "time"
"gospt/internal/commands" "gospt/src/commands"
"gospt/internal/gctx" "gospt/src/gctx"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"