package zet import ( "fmt" "log" "os" "os/exec" "path" "strconv" "strings" "code.oliverdavies.uk/opdavies/cmd-zet/internal/config" "code.oliverdavies.uk/opdavies/cmd-zet/internal/file" ) func CreateZet(title string) { zid := newZid() path := path.Join(config.GetZetDir(), strconv.Itoa(zid)) os.Mkdir(path, 0750) filePath := fmt.Sprintf("%s/index.adoc", path) f, err := os.Create(filePath) if err != nil { log.Fatal(err) } defer f.Close() _, err = fmt.Fprintf(f, "= %s", title) if err != nil { log.Fatal(err) } file.Edit(filePath) onSave(zid) } func newZid() int { cmd := exec.Command("ls", config.GetZetDir()) output, _ := cmd.CombinedOutput() zets := strings.Split(string(output), "\n") var zetCount int for _, zet := range zets { num, err := strconv.Atoi(zet) if err == nil && num > zetCount { zetCount = num } } return zetCount + 1 }