github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "io/ioutil" 7 "os" 8 "strings" 9 10 "github.com/mgutz/ansi" 11 12 . "github.com/kcmerrill/alfred/pkg/alfred" 13 ) 14 15 var ( 16 // Version of the Alfred application at compile time 17 Version = "Development" 18 // Commit hash of the Alfred application at compile time 19 Commit = "" 20 ) 21 22 func main() { 23 version := flag.Bool("version", false, "Alfred's version number") 24 disableColors := flag.Bool("no-colors", false, "Disable colors") 25 disableFormatting := flag.Bool("no-formatting", false, "Show only raw command output") 26 debug := flag.Bool("debug", false, "Only show commands to be run") 27 log := flag.String("log", "", "Log all tasks to <file>") 28 file := flag.String("f", "alfred", "Filename to use") 29 flag.Parse() 30 31 /* Giddy up! */ 32 if *version { 33 fmt.Println() 34 fmt.Println("Alfred - Even Batman needs a little help.") 35 if Version != "Development" { 36 fmt.Print("v", Version) 37 fmt.Println("@" + Commit[0:9]) 38 } else { 39 fmt.Println(Version) 40 } 41 fmt.Println() 42 fmt.Println("---") 43 fmt.Println("Made with " + ansi.ColorCode("red") + "<3" + ansi.ColorCode("reset") + " by @kcmerrill") 44 fmt.Println() 45 return 46 } 47 48 tasks := make(map[string]Task) 49 task, args := CLI(flag.Args()) 50 51 // configure out initial context with defaults 52 context := InitialContext(args) 53 54 if *disableColors { 55 context.Text = TextConfig{} 56 } 57 58 if *log != "" { 59 Log(*log, context) 60 } 61 62 if *disableFormatting { 63 context.Text.DisableFormatting = *disableFormatting 64 } 65 66 if *debug { 67 context.Text = TextConfig{} 68 context.Text.DisableFormatting = true 69 context.Debug = true 70 } 71 72 context.FileName = *file 73 74 // anything from stdin? 75 stdinFileInfo, _ := os.Stdin.Stat() 76 if stdinFileInfo.Mode()&os.ModeNamedPipe != 0 { 77 // yup. lets read it in and set it 78 stdinContent, _ := ioutil.ReadAll(os.Stdin) 79 context.Stdin = strings.TrimSpace(string(stdinContent)) 80 } 81 82 // start the task 83 NewTask(task, context, tasks) 84 }