-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (49 loc) · 1.07 KB
/
main.go
File metadata and controls
53 lines (49 loc) · 1.07 KB
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
package main
import (
"github.com/mitchellh/cli"
"github.com/voronelf/logview/core"
"io"
"os"
"strings"
)
func main() {
di := core.GetGlobalDIContainer()
var ui cli.Ui = &cli.ConcurrentUi{Ui: &cli.BasicUi{Writer: os.Stdout, ErrorWriter: os.Stderr}}
exitCode, err := doMain(di, ui, os.Stderr, os.Args[1:])
if err != nil {
ui.Error(err.Error())
}
os.Exit(exitCode)
}
func doMain(di *core.DIContainer, ui cli.Ui, helpWriter io.Writer, args []string) (int, error) {
provideCommandsDependenciesInDI(di, ui)
commands := getCommands(di)
err := di.Populate()
if err != nil {
return 1, err
}
if len(args) == 0 {
args = append(args, "watch")
} else if len(args) >= 1 {
switch args[0] {
case "-h", "--help", "--version":
// do nothing
case "help":
args[0] = "--help"
case "-v":
args[0] = "--version"
default:
if strings.Contains(args[0], "-") {
args = append([]string{"watch"}, args...)
}
}
}
c := cli.CLI{
Name: "logview",
Version: "0.9b",
Args: args,
Commands: commands,
HelpWriter: helpWriter,
}
return c.Run()
}