mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
define HomeDir and SourceDir helper functions
This commit is contained in:
parent
fc687f3174
commit
f62f3b8a02
|
@ -11,6 +11,8 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -38,13 +40,8 @@ var MigrateCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
homeDir, err := os.UserHomeDir()
|
dotDir := bbgo.HomeDir()
|
||||||
if err != nil {
|
sourceDir := bbgo.SourceDir()
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
dotDir := path.Join(homeDir, ".bbgo")
|
|
||||||
sourceDir := path.Join(dotDir, "source")
|
|
||||||
migrationDir := path.Join(sourceDir, "migrations")
|
migrationDir := path.Join(sourceDir, "migrations")
|
||||||
|
|
||||||
log.Infof("creating dir: %s", dotDir)
|
log.Infof("creating dir: %s", dotDir)
|
||||||
|
|
27
pkg/bbgo/home.go
Normal file
27
pkg/bbgo/home.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package bbgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SourceDir() string {
|
||||||
|
home := HomeDir()
|
||||||
|
return path.Join(home, "source")
|
||||||
|
}
|
||||||
|
|
||||||
|
func HomeDir() string {
|
||||||
|
homeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dotDir := path.Join(homeDir, ".bbgo")
|
||||||
|
|
||||||
|
_, err = os.Stat(dotDir)
|
||||||
|
if err != nil {
|
||||||
|
_ = os.Mkdir(dotDir, 0777)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dotDir
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user