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