From 26c49dff72ffff1daac1dfedc60da931cca1cbe9 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 25 Aug 2023 21:31:15 +0100 Subject: [PATCH] jpictl: refactor zones loading Signed-off-by: Alejandro Mery --- cmd/jpictl/config.go | 7 +++++++ cmd/jpictl/dump.go | 4 +--- cmd/jpictl/env.go | 4 +--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/jpictl/config.go b/cmd/jpictl/config.go index a65653d..a649b53 100644 --- a/cmd/jpictl/config.go +++ b/cmd/jpictl/config.go @@ -1,5 +1,7 @@ package main +import "git.jpi.io/amery/jpictl/pkg/zones" + // Config describes the repository type Config struct { Base string @@ -10,3 +12,8 @@ var cfg = &Config{ Base: "./m", 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) +} diff --git a/cmd/jpictl/dump.go b/cmd/jpictl/dump.go index faaca71..eae0801 100644 --- a/cmd/jpictl/dump.go +++ b/cmd/jpictl/dump.go @@ -9,8 +9,6 @@ import ( "github.com/burntSushi/toml" "github.com/spf13/cobra" "gopkg.in/yaml.v3" - - "git.jpi.io/amery/jpictl/pkg/zones" ) // Encoder represents an object that encodes another internally @@ -60,7 +58,7 @@ var dumpCmd = &cobra.Command{ var buf bytes.Buffer var enc Encoder - m, err := zones.New(cfg.Base, cfg.Domain) + m, err := cfg.LoadZones() if err != nil { return err } diff --git a/cmd/jpictl/env.go b/cmd/jpictl/env.go index 52471c7..37248da 100644 --- a/cmd/jpictl/env.go +++ b/cmd/jpictl/env.go @@ -4,8 +4,6 @@ import ( "os" "github.com/spf13/cobra" - - "git.jpi.io/amery/jpictl/pkg/zones" ) // Command @@ -13,7 +11,7 @@ var envCmd = &cobra.Command{ Use: "env", Short: "generates environment variables for shell scripts", RunE: func(_ *cobra.Command, _ []string) error { - m, err := zones.New(cfg.Base, cfg.Domain) + m, err := cfg.LoadZones() if err != nil { return err }