From 06152ab903efa74dd63c1e33e564ef7f84056950 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 7 Jul 2018 12:41:47 +0200 Subject: [PATCH] created project builder: cli arguments management + file check --- cmd/aicra/build-controllers.go | 9 ++++ cmd/aicra/main.go | 85 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 cmd/aicra/build-controllers.go create mode 100644 cmd/aicra/main.go diff --git a/cmd/aicra/build-controllers.go b/cmd/aicra/build-controllers.go new file mode 100644 index 0000000..b967bf7 --- /dev/null +++ b/cmd/aicra/build-controllers.go @@ -0,0 +1,9 @@ +package main + +// Builds controllers as plugins (.so) +// from the sources in the @in folder +// recursively and generate .so files +// into the @out folder with the same structure +func buildControllers(in string, out string) error { + return nil +} diff --git a/cmd/aicra/main.go b/cmd/aicra/main.go new file mode 100644 index 0000000..8dafb96 --- /dev/null +++ b/cmd/aicra/main.go @@ -0,0 +1,85 @@ +package main + +import ( + "flag" + "fmt" + "git.xdrm.io/go/aicra/clifmt" + "os" + "path/filepath" +) + +func main() { + + /* (1) Flags + ---------------------------------------------------------*/ + /* (1) controller path */ + ctlPathFlag := flag.String("c", "root", "Path to controllers' directory") + + /* (2) types path */ + typPathFlag := flag.String("t", "custom-types", "Path to custom types' directory") + + flag.Parse() + + /* (3) Get last arg: project path */ + if len(flag.Args()) < 1 { + fmt.Printf("%s\n\n", clifmt.Warn("missing argument")) + fmt.Printf("You must provide the project folder as the last argument\n") + return + } + var projectPathFlag = flag.Arg(0) + + /* (2) Get absolute paths + ---------------------------------------------------------*/ + /* (1) Get absolute project path */ + projectPath, err := filepath.Abs(projectPathFlag) + if err != nil { + fmt.Printf("invalid argument: project path\n") + return + } + /* (2) Get absolute controllers' path */ + if !filepath.IsAbs(*ctlPathFlag) { + *ctlPathFlag = filepath.Join(projectPath, *ctlPathFlag) + } + cPath, err := filepath.Abs(*ctlPathFlag) + if err != nil { + fmt.Printf("invalid argument: controllers' path\n") + return + } + + /* (3) Get absolute types' path */ + if !filepath.IsAbs(*typPathFlag) { + *typPathFlag = filepath.Join(projectPath, *typPathFlag) + } + tPath, err := filepath.Abs(*typPathFlag) + if err != nil { + fmt.Printf("invalid argument: types' path\n") + return + } + + /* (3) Check path are existing dirs + ---------------------------------------------------------*/ + /* (1) Project path */ + if stat, err := os.Stat(projectPath); err != nil || !stat.IsDir() { + fmt.Printf("%s invalid project folder - %s\n\n", clifmt.Warn(), clifmt.Color(36, projectPath)) + fmt.Printf("You must specify an existing directory path\n") + return + } + + /* (2) Controllers path */ + if stat, err := os.Stat(cPath); err != nil || !stat.IsDir() { + fmt.Printf("%s invalid controllers' folder - %s\n\n", clifmt.Warn(), clifmt.Color(36, cPath)) + fmt.Printf("You must specify an existing directory path\n") + return + } + /* (3) Types path */ + if stat, err := os.Stat(tPath); err != nil || !stat.IsDir() { + fmt.Printf("%s invalid types folder - %s\n\n", clifmt.Warn(), clifmt.Color(36, tPath)) + fmt.Printf("You must specify an existing directory path\n") + return + } + + fmt.Printf("%s\n", projectPath) + fmt.Printf("%s\n", cPath) + fmt.Printf("%s\n", tPath) + +}