Skip to content

Commit f8c56cb

Browse files
committed
improve setup to support more shells and update ci deploy
1 parent 01b6a33 commit f8c56cb

3 files changed

Lines changed: 72 additions & 25 deletions

File tree

.circleci/config.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,28 @@ jobs:
2929
deploy:
3030
docker:
3131
- image: circleci/golang:1.8
32+
environment:
33+
- GO_BUILD_OUTPUT: /go/src/github.com/bcaldwell/devctl/deploy
34+
- GO_BUILD_LDFLAGS: -X main.Version=${BUILD_VERSION} -X main.BuildDate=${BUILD_DATE}
35+
- SHA_FOLDER: /go/src/github.com/bcaldwell/devctl/deploy
36+
- SHA_VERSION: ""
3237
working_directory: /go/src/github.com/bcaldwell/devctl
3338
steps:
3439
- checkout
35-
- run: sudo apt-get update && sudo apt-get install -y python-pip
3640
- deploy:
37-
name: Release Master branch
38-
command: |
39-
if [ "${CIRCLE_BRANCH}" == "master" ]; then
40-
bash scripts/release.sh
41-
fi
41+
- run: export BUILD_DATE=`date +%Y-%m-%d:%H:%M:%S`
42+
- run: export BUILD_VERSION=`git log -1 --pretty=%B | tr " " "\n" | grep -Ei 'v[0-9]+(\.[0-9]+)*'`
43+
- run: export SHA_VERSION=$BUILD_VERSION
44+
45+
- run: go generate ./...
46+
- run: ci-scripts go/build
47+
- run: ci-scripts files/sha_firebase
48+
49+
# name: Release Master branch
50+
# command: |
51+
# if [ "${CIRCLE_BRANCH}" == "master" ]; then
52+
# bash scripts/release.sh
53+
# fi
4254

4355
workflows:
4456
version: 2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ _testmain.go
3333

3434
\.devctl/
3535

36-
# Undo global rule
36+
# Undo global rule
3737
!*.com
38+
coverage.txt

cmd/setup.go

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"io/ioutil"
66
"os"
77
"path"
8+
"regexp"
9+
"runtime"
810

9-
"github.com/bcaldwell/devctl/postCommand"
1011
printer "github.com/bcaldwell/go-printer"
1112

1213
"github.com/bcaldwell/devctl/plugins"
14+
"github.com/bcaldwell/devctl/postCommand"
1315
"github.com/bcaldwell/devctl/utilities"
1416
"github.com/spf13/cobra"
1517
)
@@ -19,14 +21,9 @@ import (
1921
// setupCmd represents the setup command
2022
var setupCmd = &cobra.Command{
2123
Use: "setup",
22-
Short: "A brief description of your command",
23-
Long: `A longer description that spans multiple lines and likely contains examples
24-
and usage of using your command. For example:
25-
26-
Cobra is a CLI library for Go that empowers applications.
27-
This application is a tool to generate the needed files
28-
to quickly create a Cobra application.`,
29-
Run: setup,
24+
Short: "Sets up devctl dependencies and install shell extensions",
25+
Long: ``,
26+
Run: setup,
3027
}
3128

3229
func init() {
@@ -35,40 +32,77 @@ func init() {
3532

3633
func setup(cmd *cobra.Command, args []string) {
3734
printer.InfoLineTop()
35+
36+
setupShellScript()
37+
38+
for _, i := range plugins.List {
39+
i.Setup()
40+
}
41+
42+
printer.InfoLineBottom()
43+
}
44+
45+
func setupShellScript() error {
3846
// create devctl.sh file in devctl home folder (HOME/.devctl)
3947
data, err := Asset("devctl.sh")
4048
utilities.Check(err, "Fetching devctl.sh file contents")
4149

4250
fileName := path.Join(devctlHomeFolder, "devctl.sh")
43-
utilities.Check(err, "Creating file "+fileName)
51+
if utilities.Check(err, "Creating file "+fileName) {
52+
return err
53+
}
4454
f, err := os.Create(fileName)
4555
defer f.Close()
4656

4757
_, err = f.Write(data)
48-
utilities.Check(err, "Writing contents to "+fileName)
58+
if utilities.Check(err, "Writing contents to "+fileName) {
59+
return err
60+
}
4961

5062
profileFile := detectProfile()
63+
fmt.Println(profileFile)
5164
profileFile = path.Join(os.Getenv("HOME"), profileFile)
5265

5366
devctlSourceString := fmt.Sprintf("[ -f %s ] && \\. %s # This loads devctl shell super powers", fileName, fileName)
5467

5568
fileData, err := ioutil.ReadFile(profileFile)
5669
if utilities.HandleError(err) {
57-
return
70+
return err
5871
}
5972
writeString := utilities.UniqueStringMerge(string(fileData), devctlSourceString)
6073
err = ioutil.WriteFile(profileFile, []byte(writeString), 0644)
6174

6275
postCommand.RunCommand("source " + fileName)
6376

6477
printer.InfoBar(printer.ColoredString("{{green:%s}} Setup shell functions"), printer.SuccessIcon)
65-
66-
for _, i := range plugins.List {
67-
i.Setup()
68-
}
69-
printer.InfoLineBottom()
78+
return nil
7079
}
7180

7281
func detectProfile() string {
73-
return ".zshrc"
82+
var re = regexp.MustCompile(`-.*\z`)
83+
shell := os.Getenv("SHELL")
84+
shell = path.Base(shell)
85+
// handle possible version suffix like `zsh-5.2`
86+
shell = re.ReplaceAllString(shell, "")
87+
88+
switch shell {
89+
case "zsh":
90+
return ".zshrc"
91+
case "bash":
92+
if runtime.GOOS == "darwin" {
93+
return ".bash_profile"
94+
}
95+
return ".bashrc"
96+
case "csh":
97+
return ".cshrc"
98+
case "fish":
99+
return ".config/fish/config.fish"
100+
case "ksh":
101+
return ".kshrc"
102+
case "sh":
103+
return ".bash_profile"
104+
case "tcsh":
105+
return ".tcshrc"
106+
}
107+
return ".bash_profile"
74108
}

0 commit comments

Comments
 (0)