main.go (1678B)
1 package main 2 3 import ( 4 "context" 5 "flag" 6 "fmt" 7 "os" 8 9 "git.defalsify.org/vise.git/engine" 10 "git.defalsify.org/vise.git/persist" 11 "git.defalsify.org/vise.git/resource" 12 "git.defalsify.org/vise.git/db" 13 fsdb "git.defalsify.org/vise.git/db/fs" 14 ) 15 16 func main() { 17 var dir string 18 var root string 19 var size uint 20 var sessionId string 21 var persistDir string 22 var initial string 23 flag.StringVar(&dir, "d", ".", "resource dir to read from") 24 flag.UintVar(&size, "s", 0, "max size of output") 25 flag.StringVar(&root, "root", "root", "entry point symbol") 26 flag.StringVar(&sessionId, "session-id", "default", "session id") 27 flag.StringVar(&persistDir, "p", "", "state persistence directory") 28 flag.StringVar(&initial, "initial", "", "initial input to pass to engine initialization") 29 flag.Parse() 30 fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir) 31 32 ctx := context.Background() 33 cfg := engine.Config{ 34 OutputSize: uint32(size), 35 SessionId: sessionId, 36 } 37 38 rsStore := fsdb.NewFsDb() 39 err := rsStore.Connect(ctx, dir) 40 if err != nil { 41 fmt.Fprintf(os.Stderr, "resource db connect error: %v", err) 42 os.Exit(1) 43 } 44 45 rs := resource.NewDbResource(rsStore) 46 rs = rs.With(db.DATATYPE_STATICLOAD) 47 en := engine.NewEngine(cfg, rs) 48 if persistDir != "" { 49 store := fsdb.NewFsDb() 50 err = store.Connect(ctx, persistDir) 51 if err != nil { 52 fmt.Fprintf(os.Stderr, "persist db connect error: %v", err) 53 os.Exit(1) 54 } 55 pe := persist.NewPersister(store) 56 en = en.WithPersister(pe) 57 } 58 59 err = engine.Loop(ctx, en, os.Stdin, os.Stdout, []byte(initial)) 60 if err != nil { 61 fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err) 62 os.Exit(1) 63 } 64 }