aboutsummaryrefslogtreecommitdiffstats
path: root/src/c_init.go
diff options
context:
space:
mode:
authorjoe <rbo@gmx.us>2025-08-28 13:41:56 +0200
committerjoe <rbo@gmx.us>2025-08-28 13:41:56 +0200
commitf170a2eb3ba93409472f901c1874c95f4f5f378e (patch)
tree7eb89698b9f7c75449814d364b0ae398cf06c53c /src/c_init.go
parentok (diff)
downloadhardflip-f170a2eb3ba93409472f901c1874c95f4f5f378e.tar.gz
hardflip-f170a2eb3ba93409472f901c1874c95f4f5f378e.tar.bz2
hardflip-f170a2eb3ba93409472f901c1874c95f4f5f378e.tar.xz
hardflip-f170a2eb3ba93409472f901c1874c95f4f5f378e.tar.zst
hardflip-f170a2eb3ba93409472f901c1874c95f4f5f378e.zip
ye
Diffstat (limited to '')
-rw-r--r--src/c_init.go67
1 files changed, 60 insertions, 7 deletions
diff --git a/src/c_init.go b/src/c_init.go
index 130ca96..c2c7779 100644
--- a/src/c_init.go
+++ b/src/c_init.go
@@ -52,6 +52,7 @@
package main
import (
+ "fmt"
"os"
"path/filepath"
@@ -85,7 +86,7 @@ type HardStyle struct {
func c_recurse_data_dir(dir, root string, opts HardOpts,
ldirs *DirsList,
name string, parent *DirsNode, depth uint16,
- ui *HardUI, load_err *[]error) {
+ load_err *[]error) {
files, err := os.ReadDir(root + dir)
if err != nil {
*load_err = append(*load_err, err)
@@ -99,12 +100,11 @@ func c_recurse_data_dir(dir, root string, opts HardOpts,
nil,
}
ldirs.add_back(&dir_node)
- i_draw_load_ui(ui)
for _, file := range files {
filename := file.Name()
if file.IsDir() == true {
c_recurse_data_dir(dir + filename + "/", root, opts, ldirs,
- file.Name(), &dir_node, depth + 1, ui, load_err)
+ file.Name(), &dir_node, depth + 1, load_err)
} else if filepath.Ext(filename) == ".yml" {
host_node, err := c_read_yaml_file(root + dir + filename)
if err != nil {
@@ -117,16 +117,14 @@ func c_recurse_data_dir(dir, root string, opts HardOpts,
}
dir_node.lhost.add_back(host_node)
}
- i_draw_load_ui(ui)
}
}
}
-func c_load_data_dir(dir string, opts HardOpts,
- ui *HardUI, load_err *[]error) (*DirsList) {
+func c_load_data_dir(dir string, opts HardOpts, load_err *[]error) (*DirsList) {
ldirs := DirsList{}
- c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1, ui, load_err)
+ c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1, load_err)
return &ldirs
}
@@ -211,3 +209,58 @@ func c_get_styles(dir string, load_err *[]error) HardStyle {
}
return styles
}
+
+func i_load_data(data_dir string,
+ opts HardOpts,
+ load_err *[]error) (*DirsList, *ItemsList, []error) {
+ ldirs := c_load_data_dir(data_dir, opts, load_err)
+ litems := c_load_litems(ldirs)
+ if len(*load_err) == 0 {
+ *load_err = nil
+ }
+ return ldirs, litems, *load_err
+}
+
+func c_init_hard(data_dir string, no_loop, search_mode bool) (*HardData) {
+ ui := HardUI{}
+ var load_err []error
+
+ fmt.Println("loading config...")
+ home_dir, _ := os.UserHomeDir()
+ opts := HardOpts{}
+ conf_dir := c_get_conf_dir(&load_err)
+ if len(conf_dir) == 0 {
+ opts = DEFAULT_OPTS
+ } else {
+ opts = c_get_options(conf_dir, &load_err)
+ }
+ if no_loop == true {
+ opts.Loop = false
+ }
+ styles := c_get_styles(conf_dir, &load_err)
+ i_init_styles(&ui, styles)
+ fmt.Println("loading data...")
+ ldirs, litems, load_err := i_load_data(data_dir, opts, &load_err)
+ data := HardData{
+ litems,
+ ldirs,
+ ui,
+ opts,
+ styles,
+ make(map[*DirsNode]*ItemsList),
+ data_dir,
+ home_dir,
+ load_err,
+ nil,
+ [][2]string{},
+ nil,
+ nil,
+ no_loop,
+ search_mode,
+ }
+ if data.opts.GPG == DEFAULT_OPTS.GPG && data.litems.head == nil {
+ data.ui.mode = WELCOME_MODE
+ data.keys = c_get_secret_gpg_keyring()
+ }
+ return &data
+}