/
hs.go
50 lines (43 loc) · 917 Bytes
/
hs.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
package main
import (
"fmt"
"github.com/julienmoumne/hotshell/cmd/hs/engine"
"github.com/julienmoumne/hotshell/cmd/hs/versioning"
"github.com/julienmoumne/hotshell/cmd/options"
"os"
)
func main() {
if err := (&hs{}).start(); err != nil {
fmt.Fprintln(os.Stderr, err)
exit(1)
}
}
type hs struct {
options options.Options
}
func (h *hs) start() error {
if err := h.parseOptions(); err != nil {
return err
}
if h.options.Version {
return h.printVersion()
}
return (&engine.Starter{}).Start(h.options)
}
func (h *hs) parseOptions() error {
var err error
h.options, err = (&options.OptionParser{}).Parse()
return err
}
func (h *hs) printVersion() error {
version, err := versioning.GetVersion()
if err != nil {
return err
}
fmt.Printf("Hotshell version %s\n", version)
return nil
}
// var is required to change the definition during tests
var exit = func(code int) {
os.Exit(code)
}