refactor: NewClientWithContext -> New, and use server only
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-09-05 00:41:31 +02:00
parent dac679db48
commit 07a43cb314
14 changed files with 55 additions and 54 deletions

View File

@ -13,19 +13,20 @@ import (
"github.com/urfave/cli/v2"
)
func getAppsHost(appName string) string {
// getAppServer retrieves the server of an app.
func getAppServer(appName string) string {
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
var host string
var server string
if app, ok := appFiles[appName]; ok {
host = app.Server
server = app.Server
} else {
logrus.Fatalf(`app "%s" does not exist`, appName)
}
return host
return server
}
var appVolumeListCommand = &cli.Command{
@ -37,10 +38,10 @@ var appVolumeListCommand = &cli.Command{
if appName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided!"))
}
host := getAppsHost(appName)
ctx := context.Background()
volumeList, err := client.GetVolumes(ctx, host, appName)
server := getAppServer(appName)
volumeList, err := client.GetVolumes(ctx, server, appName)
if err != nil {
logrus.Fatal(err)
}
@ -71,9 +72,9 @@ var appVolumeRemoveCommand = &cli.Command{
if appName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided!"))
}
host := getAppsHost(appName)
server := getAppServer(appName)
ctx := context.Background()
volumeList, err := client.GetVolumes(ctx, host, appName)
volumeList, err := client.GetVolumes(ctx, server, appName)
if err != nil {
logrus.Fatal(err)
}
@ -93,7 +94,7 @@ var appVolumeRemoveCommand = &cli.Command{
volumesToRemove = volumeNames
}
err = client.RemoveVolumes(ctx, host, volumesToRemove, internal.Force)
err = client.RemoveVolumes(ctx, server, volumesToRemove, internal.Force)
if err != nil {
logrus.Fatal(err)
}