增加 init提示

This commit is contained in:
dengsgo 2019-12-17 16:10:33 +08:00
parent 04c46435d4
commit 46df7a206a
2 changed files with 20 additions and 9 deletions

View File

@ -24,6 +24,8 @@ const (
var ( var (
projectFolder = "." projectFolder = "."
filegirlYamlName = "filegirl.yaml"
cfg *FileGirl cfg *FileGirl
watcher *fsnotify.Watcher watcher *fsnotify.Watcher
@ -48,18 +50,18 @@ type changedFile struct {
func parseConfig() { func parseConfig() {
cfg = new(FileGirl) cfg = new(FileGirl)
fc, err := ioutil.ReadFile(projectFolder + "/filegirl.yaml") fc, err := ioutil.ReadFile(getFileGirlPath())
if err != nil { if err != nil {
log.Println(PreError, "the filegirl.yaml file in", projectFolder, "is not exist! ", err) log.Println(PreError, "The filegirl.yaml file in", projectFolder, "is not exist! ", err)
fmt.Print(firstRunHelp) fmt.Print(firstRunHelp)
logAndExit("fileboy unable to run.") logAndExit("Fileboy unable to run.")
} }
err = yaml.Unmarshal(fc, cfg) err = yaml.Unmarshal(fc, cfg)
if err != nil { if err != nil {
logAndExit(PreError, "parsed filegirl.yaml failed: ", err) logAndExit(PreError, "Parsed filegirl.yaml failed: ", err)
} }
if cfg.Core.Version > Version { if cfg.Core.Version > Version {
logAndExit(PreError, "current fileboy support max version : ", Version) logAndExit(PreError, "Current fileboy support max version : ", Version)
} }
// init map // init map
cfg.Monitor.TypesMap = map[string]bool{} cfg.Monitor.TypesMap = map[string]bool{}
@ -248,12 +250,17 @@ func parseArgs() {
c := os.Args[1] c := os.Args[1]
switch c { switch c {
case "init": case "init":
err := ioutil.WriteFile(projectFolder+"/filegirl.yaml", []byte(exampleFileGirl), 0644) _, err := ioutil.ReadFile(getFileGirlPath())
if err == nil {
log.Println(PreError, "Profile filegirl.yaml already exists.")
logAndExit("If you want to regenerate filegirl.yaml, delete it first")
}
err = ioutil.WriteFile(getFileGirlPath(), []byte(exampleFileGirl), 0644)
if err != nil { if err != nil {
log.Println(PreError, "error create filegirl.yaml config! ", err) log.Println(PreError, "Profile filegirl.yaml create failed! ", err)
return return
} }
log.Println("create filegirl.yaml ok") log.Println("Profile filegirl.yaml created ok")
return return
case "exec": case "exec":
parseConfig() parseConfig()
@ -270,6 +277,10 @@ func parseArgs() {
} }
} }
func getFileGirlPath() string {
return projectFolder + "/" + filegirlYamlName
}
func show() { func show() {
fmt.Print(logo) fmt.Print(logo)
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())

View File

@ -78,5 +78,5 @@ func inStrArray(s string, arr []string) bool {
func logAndExit(v ...interface{}) { func logAndExit(v ...interface{}) {
log.Println(v...) log.Println(v...)
os.Exit(0) os.Exit(15)
} }