summaryrefslogtreecommitdiffhomepage
path: root/internal/config
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/init.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/internal/config/init.go b/internal/config/init.go
new file mode 100644
index 000000000..e0a1c6da7
--- /dev/null
+++ b/internal/config/init.go
@@ -0,0 +1,61 @@
+package config
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+)
+
+const (
+ // InitFlagFilename is the name of the file that indicates whether the project has been initialized
+ InitFlagFilename = "init"
+)
+
+// ProjectInitFlag represents the initialization status for a project directory
+type ProjectInitFlag struct {
+ Initialized bool `json:"initialized"`
+}
+
+// ShouldShowInitDialog checks if the initialization dialog should be shown for the current directory
+func ShouldShowInitDialog() (bool, error) {
+ if cfg == nil {
+ return false, fmt.Errorf("config not loaded")
+ }
+
+ // Create the flag file path
+ flagFilePath := filepath.Join(cfg.Data.Directory, InitFlagFilename)
+
+ // Check if the flag file exists
+ _, err := os.Stat(flagFilePath)
+ if err == nil {
+ // File exists, don't show the dialog
+ return false, nil
+ }
+
+ // If the error is not "file not found", return the error
+ if !os.IsNotExist(err) {
+ return false, fmt.Errorf("failed to check init flag file: %w", err)
+ }
+
+ // File doesn't exist, show the dialog
+ return true, nil
+}
+
+// MarkProjectInitialized marks the current project as initialized
+func MarkProjectInitialized() error {
+ if cfg == nil {
+ return fmt.Errorf("config not loaded")
+ }
+ // Create the flag file path
+ flagFilePath := filepath.Join(cfg.Data.Directory, InitFlagFilename)
+
+ // Create an empty file to mark the project as initialized
+ file, err := os.Create(flagFilePath)
+ if err != nil {
+ return fmt.Errorf("failed to create init flag file: %w", err)
+ }
+ defer file.Close()
+
+ return nil
+}
+