jpictl: refactor zones loading
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "git.jpi.io/amery/jpictl/pkg/zones"
|
||||||
|
|
||||||
// Config describes the repository
|
// Config describes the repository
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Base string
|
Base string
|
||||||
@@ -10,3 +12,8 @@ var cfg = &Config{
|
|||||||
Base: "./m",
|
Base: "./m",
|
||||||
Domain: "m.jpi.cloud",
|
Domain: "m.jpi.cloud",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadZones loads all zones and machines in the config directory
|
||||||
|
func (cfg *Config) LoadZones() (*zones.Zones, error) {
|
||||||
|
return zones.New(cfg.Base, cfg.Domain)
|
||||||
|
}
|
||||||
|
|||||||
+1
-3
@@ -9,8 +9,6 @@ import (
|
|||||||
"github.com/burntSushi/toml"
|
"github.com/burntSushi/toml"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"git.jpi.io/amery/jpictl/pkg/zones"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Encoder represents an object that encodes another internally
|
// Encoder represents an object that encodes another internally
|
||||||
@@ -60,7 +58,7 @@ var dumpCmd = &cobra.Command{
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
var enc Encoder
|
var enc Encoder
|
||||||
|
|
||||||
m, err := zones.New(cfg.Base, cfg.Domain)
|
m, err := cfg.LoadZones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -4,8 +4,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"git.jpi.io/amery/jpictl/pkg/zones"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command
|
// Command
|
||||||
@@ -13,7 +11,7 @@ var envCmd = &cobra.Command{
|
|||||||
Use: "env",
|
Use: "env",
|
||||||
Short: "generates environment variables for shell scripts",
|
Short: "generates environment variables for shell scripts",
|
||||||
RunE: func(_ *cobra.Command, _ []string) error {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
m, err := zones.New(cfg.Base, cfg.Domain)
|
m, err := cfg.LoadZones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user