mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +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"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/bbgo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -38,13 +40,8 @@ var MigrateCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dotDir := path.Join(homeDir, ".bbgo")
|
||||
sourceDir := path.Join(dotDir, "source")
|
||||
dotDir := bbgo.HomeDir()
|
||||
sourceDir := bbgo.SourceDir()
|
||||
migrationDir := path.Join(sourceDir, "migrations")
|
||||
|
||||
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