wisdom.go (882B)
1 package main 2 3 import ( 4 "flag" 5 "os" 6 "path/filepath" 7 8 "code.dwrz.net/src/pkg/log" 9 "code.dwrz.net/src/pkg/terminal" 10 "code.dwrz.net/src/pkg/wisdom" 11 ) 12 13 func main() { 14 var l = log.New(os.Stderr) 15 16 flag.Parse() 17 18 dir, err := os.UserConfigDir() 19 if err != nil { 20 l.Error.Fatalf("failed to get user config dir: %v", err) 21 } 22 23 var params = wisdom.Parameters{ 24 Log: l, 25 Path: filepath.Join(dir, "wisdom"), 26 } 27 28 terminal, err := terminal.New(os.Stdin.Fd()) 29 if err != nil { 30 l.Error.Printf("failed to create terminal: %v", err) 31 } 32 33 if terminal != nil { 34 size, err := terminal.Size() 35 if err != nil { 36 l.Error.Printf("failed to get terminal size: %v", err) 37 } 38 39 params.Size = *size 40 } 41 42 w, err := wisdom.New(params) 43 if err != nil { 44 l.Error.Fatalf("failed to create command: %v", err) 45 } 46 47 if err := w.Command(flag.CommandLine.Args()); err != nil { 48 l.Error.Fatal(err) 49 } 50 }