mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
// Copyright (C) 2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package lpmintegration
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/luxfi/cli/v2/pkg/application"
|
|
"github.com/luxfi/cli/v2/pkg/constants"
|
|
"github.com/luxfi/cli/v2/pkg/ux"
|
|
)
|
|
|
|
// Returns alias
|
|
func AddRepo(app *application.Lux, repoURL *url.URL, branch string) (string, error) {
|
|
alias, err := getAlias(repoURL)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if alias == constants.DefaultLuxPackage {
|
|
ux.Logger.PrintToUser("Lux Plugins Core already installed, skipping...")
|
|
return "", nil
|
|
}
|
|
|
|
repoStr := repoURL.String()
|
|
|
|
if path.Ext(repoStr) != constants.GitExtension {
|
|
repoStr += constants.GitExtension
|
|
}
|
|
|
|
fmt.Println("Installing repo")
|
|
|
|
return alias, app.Apm.AddRepository(alias, repoStr, branch)
|
|
}
|
|
|
|
func UpdateRepos(app *application.Lux) error {
|
|
return app.Apm.Update()
|
|
}
|
|
|
|
func InstallVM(app *application.Lux, subnetKey string) error {
|
|
vms, err := getVMsInSubnet(app, subnetKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
splitKey := strings.Split(subnetKey, ":")
|
|
if len(splitKey) != 2 {
|
|
return fmt.Errorf("invalid key: %s", subnetKey)
|
|
}
|
|
|
|
repo := splitKey[0]
|
|
|
|
for _, vm := range vms {
|
|
toInstall := repo + ":" + vm
|
|
fmt.Println("Installing vm:", toInstall)
|
|
err = app.Apm.Install(toInstall)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|