-
Notifications
You must be signed in to change notification settings - Fork 3
/
switch.go
101 lines (84 loc) · 2.71 KB
/
switch.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// go-aah/tools/aah source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"path"
"gopkg.in/urfave/cli.v1"
)
const (
releaseBranchName = "master"
edgeBranchName = "v0-edge"
)
var switchCmd = cli.Command{
Name: "switch",
Aliases: []string{"s"},
Usage: "Switch between aah release and edge version (beta)",
Description: `Provides an ability to switch between aah release and edge version.
Examples of short and long flags:
aah s
aah switch
To check which version is currently active:
aah s -w
aah switch --whoami
Note:
- Currently it works with only GOPATH. Gradually I will add vendorize support too.
- Currently it is in beta, help with your feedback for improvements.
- It always operates on latest version, specific version is not supported.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "w, whoami",
Usage: "To know which version is currently active",
},
},
Action: switchAction,
}
func switchAction(c *cli.Context) error {
branchName := gitBranchName(libDir("aah"))
if c.Bool("w") || c.Bool("whoami") {
if branchName == releaseBranchName {
fmt.Printf("You're using aah 'release' version.\n\n")
} else { // treat every branch as 'edge' version expect branch 'master'.
fmt.Printf("You're using aah 'edge' version, your feedback is appreciated.\n\n")
}
return nil
}
var toBranch string
var friendlyName string
if branchName == releaseBranchName {
toBranch = edgeBranchName
friendlyName = "edge"
} else {
toBranch = releaseBranchName
friendlyName = "release"
}
fmt.Printf("Switching aah version to '%s' ...\n\n", friendlyName)
// Switch between release and edge version
for _, lib := range libNames {
dir := libDir(lib)
// Checkout the branch
if err := gitCheckout(dir, toBranch); err != nil {
fatalf("Error occurred which switching aah version: %s", err)
}
// Refresh the branch codebase
if err := gitPull(dir); err != nil {
fatalf("Unable to refresh library: %s.%s", lib, versionSeries)
}
}
// Refresh dependencies in grace mode
if err := goGet(path.Join(importPrefix, "aah.v0", "...")); err != nil {
fatalf("Unable to refresh dependencies: %s", err)
}
// Install aah CLI for the switched version
args := []string{"install", path.Join(importPrefix, "tools.v0", "aah")}
if _, err := execCmd(gocmd, args, false); err != nil {
fatalf("Unable to compile CLI tool: %s", err)
}
if toBranch == releaseBranchName {
fmt.Printf("You have successfully switched to aah 'release' version.\n\n")
} else {
fmt.Printf("You have successfully switched to aah 'edge' version, your feedback is appreciated.\n\n")
}
return nil
}