Compare commits

...

3 Commits

Author SHA1 Message Date
amery c9f2d03dc5 jpictl: initial env command [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-21 19:05:12 +00:00
amery 927810fa24 zones: WriteEnv() [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-21 19:05:12 +00:00
amery 44ea514e15 zones: WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-21 19:02:28 +00:00
5 changed files with 111 additions and 0 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("./m")
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
}
+7
View File
@@ -0,0 +1,7 @@
package zones
// A Machine is a machine on a Zone
type Machine struct {
zone *Zone
name string
}
+29
View File
@@ -0,0 +1,29 @@
package zones
import (
"io/fs"
"log"
)
func (m *Zones) scan() error {
var zones []Zone
// each directory is a zone
entries, err := fs.ReadDir(m.dir, ".")
if err != nil {
return err
}
for _, e := range entries {
if e.IsDir() {
z := Zone{
zones: m,
name: e.Name(),
}
log.Print(z)
zones = append(zones, z)
}
}
return nil
}
+39
View File
@@ -0,0 +1,39 @@
package zones
import (
"io/fs"
"os"
)
// Zone represents one zone in a cluster
type Zone struct {
zones *Zones
id int
name string
}
// Zones represents all zones in a cluster
type Zones struct {
dir fs.FS
zones []Zone
}
// NewFS builds a [Zones] tree using the given directory
func NewFS(dir fs.FS) (*Zones, error) {
z := &Zones{
dir: dir,
}
if err := z.scan(); err != nil {
return nil, err
}
return z, nil
}
// New builds a [Zones] tree using the given directory
func New(dir string) (*Zones, error) {
return NewFS(os.DirFS(dir))
}