Skip to content

Commit

Permalink
feat: allow configuring registry URL/dir
Browse files Browse the repository at this point in the history
Fixes #99
  • Loading branch information
agaffney committed Mar 13, 2024
1 parent 45cf83e commit 265ef47
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 72 deletions.
24 changes: 4 additions & 20 deletions cmd/cardano-up/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ func contextListCommand() *cobra.Command {
Use: "list",
Short: "List available contexts",
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
activeContext, _ := pm.ActiveContext()
contexts := pm.Contexts()
slog.Info("Contexts (* is active):\n")
Expand Down Expand Up @@ -106,11 +102,7 @@ func contextSelectCommand() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
if err := pm.SetActiveContext(args[0]); err != nil {
slog.Error(fmt.Sprintf("failed to set active context: %s", err))
os.Exit(1)
Expand Down Expand Up @@ -139,11 +131,7 @@ func contextCreateCommand() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
tmpContextName := args[0]
tmpContext := pkgmgr.Context{
Description: contextFlags.description,
Expand Down Expand Up @@ -174,11 +162,7 @@ func contextDeleteCommand() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
if err := pm.DeleteContext(args[0]); err != nil {
slog.Error(fmt.Sprintf("failed to delete context: %s", err))
os.Exit(1)
Expand Down
8 changes: 1 addition & 7 deletions cmd/cardano-up/down.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package main

import (
"fmt"
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/pkgmgr"
"github.com/spf13/cobra"
)

Expand All @@ -15,11 +13,7 @@ func downCommand() *cobra.Command {
Short: "Stops all Docker containers",
Long: `Stops all running Docker containers for installed packages in the current context.`,
RunE: func(cmd *cobra.Command, args []string) error {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
if err := pm.Down(); err != nil {
slog.Error(err.Error())
os.Exit(1)
Expand Down
8 changes: 1 addition & 7 deletions cmd/cardano-up/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ package main

import (
"errors"
"fmt"
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/pkgmgr"
"github.com/spf13/cobra"
)

Expand All @@ -39,11 +37,7 @@ func infoCommand() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
if err := pm.Info(args[0]); err != nil {
slog.Error(err.Error())
os.Exit(1)
Expand Down
7 changes: 1 addition & 6 deletions cmd/cardano-up/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/pkgmgr"
"github.com/spf13/cobra"
)

Expand All @@ -47,11 +46,7 @@ func installCommand() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
activeContextName, activeContext := pm.ActiveContext()
// Update context network if specified
if installFlags.network != "" {
Expand Down
13 changes: 2 additions & 11 deletions cmd/cardano-up/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main
import (
"fmt"
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/pkgmgr"
"github.com/spf13/cobra"
Expand All @@ -32,11 +31,7 @@ func listAvailableCommand() *cobra.Command {
Use: "list-available",
Short: "List available packages",
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
packages := pm.AvailablePackages()
slog.Info("Available packages:\n")
slog.Info(
Expand Down Expand Up @@ -76,11 +71,7 @@ func listCommand() *cobra.Command {
Use: "list",
Short: "List installed packages",
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
activeContextName, _ := pm.ActiveContext()
var packages []pkgmgr.InstalledPackage
if listFlags.all {
Expand Down
23 changes: 23 additions & 0 deletions cmd/cardano-up/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
package main

import (
"fmt"
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/internal/consolelog"
"github.com/blinklabs-io/cardano-up/pkgmgr"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -80,3 +82,24 @@ func main() {
os.Exit(1)
}
}

func createPackageManager() *pkgmgr.PackageManager {
cfg, err := pkgmgr.NewDefaultConfig()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
// Allow setting registry URL/dir via env var
if url, ok := os.LookupEnv("REGISTRY_URL"); ok {
cfg.RegistryUrl = url
}
if dir, ok := os.LookupEnv("REGISTRY_DIR"); ok {
cfg.RegistryDir = dir
}
pm, err := pkgmgr.NewPackageManager(cfg)
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
return pm
}
8 changes: 1 addition & 7 deletions cmd/cardano-up/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ package main

import (
"errors"
"fmt"
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/pkgmgr"
"github.com/spf13/cobra"
)

Expand All @@ -42,11 +40,7 @@ func uninstallCommand() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
// Uninstall package
if err := pm.Uninstall(uninstallFlags.keepData, args[0]); err != nil {
slog.Error(err.Error())
Expand Down
8 changes: 1 addition & 7 deletions cmd/cardano-up/up.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package main

import (
"fmt"
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/pkgmgr"
"github.com/spf13/cobra"
)

Expand All @@ -15,11 +13,7 @@ func upCommand() *cobra.Command {
Short: "Starts all Docker containers",
Long: `Starts all stopped Docker containers for installed packages in the current context.`,
RunE: func(cmd *cobra.Command, args []string) error {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
if err := pm.Up(); err != nil {
slog.Error(err.Error())
os.Exit(1)
Expand Down
8 changes: 1 addition & 7 deletions cmd/cardano-up/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ package main

import (
"errors"
"fmt"
"log/slog"
"os"

"github.com/blinklabs-io/cardano-up/pkgmgr"
"github.com/spf13/cobra"
)

Expand All @@ -38,11 +36,7 @@ func upgradeCommand() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
pm, err := pkgmgr.NewDefaultPackageManager()
if err != nil {
slog.Error(fmt.Sprintf("failed to create package manager: %s", err))
os.Exit(1)
}
pm := createPackageManager()
// Upgrade requested package
if err := pm.Upgrade(args[0]); err != nil {
slog.Error(err.Error())
Expand Down

0 comments on commit 265ef47

Please sign in to comment.