From 6f7b5f5aef9e7c08c26f54ec14f44028e8221a02 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Sat, 23 Mar 2019 02:52:29 +0000 Subject: [PATCH] farm: new package to handle set of cli contexts Signed-off-by: Tibor Vass --- farm/farm.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 farm/farm.go diff --git a/farm/farm.go b/farm/farm.go new file mode 100644 index 00000000..be6ec690 --- /dev/null +++ b/farm/farm.go @@ -0,0 +1,45 @@ +package farm + +import ( + "os" + "path/filepath" +) + +// Name of a Farm. +type Name string + +// Context name of docker cli context. +type Context string + +// Platform represents the platform OS/Architecture of a Context. +type Platform string + +// Farm is a set of Context objects mapped to a Platform. +// This could change in the future to be more generic. +type Farm map[Platform]Context + +// Ville is a set of Farms. +type Ville struct { + Farms map[Name]Farm + ActiveFarm Name +} + +func LoadVille(root string) (*Ville, error) { + if err := os.MkdirAll(root, 0755); err != nil { + return err + } + v := &Ville{Farms: make(map[Name]Farm)} + err := filepath.Walk(root, func(p string, fi os.FileInfo, err error) error { + if err != nil { + return err + } + if p == root { + return nil + } + if fi.IsDir() { + return filepath.SkipDir + } + v.Farms[fi.Name()] = map[Platform]Context{} + }) + return v, err +}