aboutsummaryrefslogtreecommitdiffstats
path: root/src/i_insert.go
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-04-09 20:20:20 +0200
committerJoe <rbo@gmx.us>2024-04-09 20:20:20 +0200
commitec347cdd1527fbfe21492c0df378073537cff1a8 (patch)
tree97b606bc214de1fa6d51107912779e2aa402d805 /src/i_insert.go
parentgoing good (diff)
downloadhardflip-ec347cdd1527fbfe21492c0df378073537cff1a8.tar.gz
hardflip-ec347cdd1527fbfe21492c0df378073537cff1a8.tar.bz2
hardflip-ec347cdd1527fbfe21492c0df378073537cff1a8.tar.xz
hardflip-ec347cdd1527fbfe21492c0df378073537cff1a8.tar.zst
hardflip-ec347cdd1527fbfe21492c0df378073537cff1a8.zip
cursor fucked up but ye
Diffstat (limited to '')
-rw-r--r--src/i_insert.go34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/i_insert.go b/src/i_insert.go
index ea1310d..5028c49 100644
--- a/src/i_insert.go
+++ b/src/i_insert.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/i_insert.go
- * Tue Apr 09 14:56:56 2024
+ * Tue Apr 09 15:36:02 2024
* Joe
*
* insert a new host
@@ -53,13 +53,14 @@ package main
import (
"errors"
- "fmt"
"os"
+ "regexp"
"strconv"
"strings"
"github.com/gdamore/tcell/v2"
"gopkg.in/yaml.v3"
+ "k8s.io/apimachinery/pkg/util/uuid"
)
func i_insert_format_filename(name, path string) string {
@@ -68,21 +69,36 @@ func i_insert_format_filename(name, path string) string {
if len(name) == 0 {
return ""
}
+ re := regexp.MustCompile("[^a-zA-Z0-9]+")
+ replace := "_"
+ str = re.ReplaceAllString(str, replace)
+ _, err := os.Stat(path + str + ".yml")
+ for err == nil {
+ uid := uuid.NewUUID()
+ str += "_" + string(uid[0:4])
+ _, err = os.Stat(path + str + ".yml")
+ }
str = strings.ToLower(str) + ".yml"
return str
}
func i_insert_host(data *HardData, insert *HostNode) {
- data.ui.s.Fini()
- fmt.Println(i_insert_format_filename(insert.Name,
- data.data_dir + insert.parent.path()))
- fmt.Println(data.data_dir + insert.parent.path())
- os.Exit(0)
- _, err := yaml.Marshal(insert)
+ filename := i_insert_format_filename(insert.Name,
+ data.data_dir + insert.parent.path())
+ insert.filename = filename
+ fmt, err := yaml.Marshal(insert)
+ if err != nil {
+ c_error_mode("yaml", err, &data.ui)
+ data.insert = nil
+ return
+ }
+ err = os.WriteFile(data.data_dir + insert.parent.path() + filename,
+ fmt, 0644)
if err != nil {
+ c_error_mode("can't write file", err, &data.ui)
+ data.insert = nil
return
}
- // err = os.WriteFile(i_insert_format_filename(insert.Name))
item := &ItemsNode{
data.litems.curr.ID + 1,
nil,