Browse Source

jpictl: refactor zones loading

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 1 year ago
parent
commit
26c49dff72
  1. 7
      cmd/jpictl/config.go
  2. 4
      cmd/jpictl/dump.go
  3. 4
      cmd/jpictl/env.go

7
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)
}

4
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
}

4
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
}

Loading…
Cancel
Save