Compare commits

..

2 Commits

Author SHA1 Message Date
amery 29dfde5e46 jpictl: initial env command [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-22 19:39:55 +00:00
amery 93aac4c04c zones: WriteEnv() [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-22 19:39:55 +00:00
4 changed files with 44 additions and 13 deletions
+27
View File
@@ -0,0 +1,27 @@
package main
import (
"os"
"github.com/spf13/cobra"
"git.jpi.io/amery/jpictl/pkg/zones"
)
// Command
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)
if err != nil {
return err
}
return m.WriteEnv(os.Stdout)
},
}
func init() {
rootCmd.AddCommand(envCmd)
}
+9
View File
@@ -0,0 +1,9 @@
// Package zones abstracts the cluster zones
package zones
import "io"
// WriteEnv generates environment variables for shell scripts
func (*Zones) WriteEnv(io.Writer) error {
return nil
}
+4 -3
View File
@@ -31,9 +31,10 @@ func (m *Zones) scan() error {
func (m *Zones) scanMachines() error {
var err error
m.ForEachMachine(func(p *Machine) bool {
err = p.scan()
return err != nil
m.ForEachMachine(func(p *Machine) {
if err == nil {
err = p.scan()
}
})
return err
}
+4 -10
View File
@@ -32,24 +32,18 @@ type Zones struct {
}
// ForEachMachine calls a function for each Machine in the cluster
func (m *Zones) ForEachMachine(fn func(*Machine) bool) {
func (m *Zones) ForEachMachine(fn func(*Machine)) {
for _, z := range m.Zones {
for _, p := range z.Machines {
if fn(p) {
// terminate
return
}
fn(p)
}
}
}
// ForEachZone calls a function for each Zone in the cluster
func (m *Zones) ForEachZone(fn func(*Zone) bool) {
func (m *Zones) ForEachZone(fn func(*Zone)) {
for _, p := range m.Zones {
if fn(p) {
// terminate
return
}
fn(p)
}
}