-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
61 lines (49 loc) · 1.38 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
package main
import (
"fmt"
"log"
"regexp"
"github.com/appcelerator/amp/cli"
"github.com/appcelerator/amp/docker/docker/pkg/term"
)
var (
// Version is set with a linker flag (see Makefile)
Version string
// Build is set with a linker flag (see Makefile)
Build string
//address string
cfg *cli.Configuration
)
func main() {
// Initial configuration (before processing environment and flags)
cfg = &cli.Configuration{
Server: cli.DefaultAddress + cli.DefaultPort,
}
// Read the cli config
if err := cli.ReadClientConfig(cfg); err != nil {
log.Fatalln(err)
}
// Build and Version cannot be overridden
cfg.Build = Build
cfg.Version = Version
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()
c := cli.NewCLI(stdin, stdout, stderr, cfg)
cmd := newRootCommand(c)
if err := cmd.Execute(); err != nil {
// cobra command error looks like: unknown command "foo" for "amp"
// replace it with error that is more consistent with errors for flags and args.
e := err.Error()
pattern := "unknown command \"([^\"]*)\""
re := regexp.MustCompile(pattern)
match := re.FindStringSubmatch(e)
if match != nil {
e = fmt.Sprintf("not an amp command: %s\nSee '%s --help", match[1], cmd.CommandPath())
}
c.Console().Errorln(e)
cli.Exit(1)
}
}
func showVersion() {
fmt.Printf("amp version %s, build %s\n", Version, Build)
}