github.com/unirita/cuto@v0.9.8-0.20160830082821-aa6652f877b7/flowgen/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 9 "github.com/unirita/cuto/flowgen/converter" 10 ) 11 12 const usage = `Usage : 13 flowgen [file_name] 14 15 Copyright 2015 unirita Inc. 16 ` 17 18 const ( 19 rc_OK = 0 20 rc_PARAM_ERROR = 1 21 rc_SYNTAX_ERROR = 2 22 rc_OUTPUT_ERROR = 4 23 ) 24 25 func main() { 26 os.Exit(realMain()) 27 } 28 29 func realMain() int { 30 if len(os.Args) != 2 { 31 fmt.Println(usage) 32 return rc_PARAM_ERROR 33 } 34 35 path := os.Args[1] 36 elm, err := converter.ParseFile(path) 37 if err != nil { 38 fmt.Println(err) 39 return rc_SYNTAX_ERROR 40 } 41 42 definitions := converter.GenerateDefinitions(elm) 43 err = converter.ExportFile(convertExtension(path, ".bpmn"), definitions) 44 if err != nil { 45 fmt.Println(err) 46 return rc_OUTPUT_ERROR 47 } 48 49 return rc_OK 50 } 51 52 func convertExtension(path string, afterExt string) string { 53 dir, base := filepath.Split(path) 54 ext := filepath.Ext(path) 55 56 if ext != "" { 57 base = strings.Replace(base, ext, "", -1) 58 } 59 base = base + afterExt 60 61 return filepath.Join(dir, base) 62 }