Skip to content

Commit 8097802

Browse files
committed
start moving update logic to binary. Rewrite bash file to not assume install location and use /bin install
1 parent 4d6b38e commit 8097802

8 files changed

Lines changed: 297 additions & 131 deletions

File tree

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
# - vendor
2121

2222
- setup_remote_docker
23+
- gem install ci-scripts
2324

24-
- run: bash scripts/go.test.sh
25+
- run: ci-scripts go/test
2526
- run: bash <(curl -s https://codecov.io/bash)
2627

2728
deploy:

cmd/bindata.go

Lines changed: 235 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/devctl.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package cmd
33
import (
44
"os"
55
"path"
6+
"runtime"
67

78
"github.com/bcaldwell/devctl/parser"
89
"github.com/bcaldwell/devctl/plugins"
910
"github.com/bcaldwell/devctl/postCommand"
1011
"github.com/bcaldwell/devctl/shell"
12+
"github.com/bcaldwell/devctl/utilities"
1113
"github.com/bcaldwell/go-printer"
1214
"github.com/spf13/cobra"
1315
)
@@ -22,6 +24,8 @@ var BuildDate string
2224
var Verbose bool
2325
var DryRun bool
2426

27+
var devctlHomeFolder string
28+
2529
// devctlCmd represents the base command when called without any subcommands
2630
var devctlCmd = &cobra.Command{
2731
Use: "devctl",
@@ -78,7 +82,14 @@ func init() {
7882
// initConfig reads in config file and ENV variables if set.
7983
func initConfig() {
8084

81-
cfgFile := path.Join(os.Getenv("HOME"), ".devctlconfig")
85+
devctlHomeFolder = path.Join(userHomeDir(), ".devctl")
86+
_, folderExists := os.Stat(devctlHomeFolder)
87+
if os.IsNotExist(folderExists) {
88+
err := os.MkdirAll(devctlHomeFolder, os.ModePerm)
89+
utilities.Check(err, "Creating folder "+devctlHomeFolder)
90+
}
91+
92+
cfgFile := path.Join(devctlHomeFolder, "config.yml")
8293

8394
shell.DryRun = DryRun
8495
postCommand.DryRun = DryRun
@@ -104,3 +115,14 @@ func initConfig() {
104115
func persistentPostRun(cmd *cobra.Command, args []string) {
105116
postCommand.Write()
106117
}
118+
119+
func userHomeDir() string {
120+
if runtime.GOOS == "windows" {
121+
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
122+
if home == "" {
123+
home = os.Getenv("USERPROFILE")
124+
}
125+
return home
126+
}
127+
return os.Getenv("HOME")
128+
}

cmd/setup.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package cmd
22

33
import (
4+
"os"
5+
"path"
6+
7+
"github.com/bcaldwell/devctl/postCommand"
8+
49
"github.com/bcaldwell/devctl/plugins"
10+
"github.com/bcaldwell/devctl/utilities"
511
"github.com/spf13/cobra"
612
)
713

14+
//go:generate go-bindata -prefix "../" -o bindata.go -pkg cmd ../devctl.sh
15+
816
// setupCmd represents the setup command
917
var setupCmd = &cobra.Command{
1018
Use: "setup",
@@ -20,21 +28,24 @@ to quickly create a Cobra application.`,
2028

2129
func init() {
2230
devctlCmd.AddCommand(setupCmd)
31+
}
2332

24-
// Here you will define your flags and configuration settings.
33+
func setup(cmd *cobra.Command, args []string) {
34+
data, err := Asset("devctl.sh")
35+
utilities.Check(err, "Fetching devctl.sh file contents")
2536

26-
// Cobra supports Persistent Flags which will work for this command
27-
// and all subcommands, e.g.:
28-
// setupCmd.PersistentFlags().String("foo", "", "A help for foo")
37+
fileName := path.Join(devctlHomeFolder, "devctl.sh")
38+
utilities.Check(err, "Creating file "+fileName)
39+
f, err := os.Create(fileName)
40+
defer f.Close()
2941

30-
// Cobra supports local flags which will only run when this command
31-
// is called directly, e.g.:
32-
// setupCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
42+
_, err = f.Write(data)
43+
utilities.Check(err, "Writing contents to "+fileName)
3344

34-
}
45+
// TODO: source file
46+
47+
postCommand.RunCommand("source " + fileName)
3548

36-
func setup(cmd *cobra.Command, args []string) {
37-
// TODO: Work your own magic here
3849
for _, i := range plugins.List {
3950
i.Setup()
4051
}

0 commit comments

Comments
 (0)