ref(cfg): extend init command with additional props (#42)

* feat(v_config): changed vault configuration

* ref(cfg): extend init cmd with config props
This commit is contained in:
Kristian 2026-05-27 21:01:58 +02:00 committed by GitHub
parent 38b4cb815f
commit 0eeb588983
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 72 additions and 47 deletions

View file

@ -11,11 +11,22 @@ import (
) )
type initializeCommand struct { type initializeCommand struct {
VaultName string `json:"vaultName"` Config Config `json:"config"`
VaultPath string `json:"vaultPath"` }
TemplateDirectory string `json:"templateDirectory"`
ExcludeIndexFiles []string `json:"excludeIndexFiles"` type Config struct {
OverrideDefaultIgnores bool `json:"overrideDefaultIgnores"` VaultName string `json:"vault_name"`
VaultPath string `json:"vault_path"`
TemplatesDir string `json:"templates_dir"`
ExcludeIndexFiles []string `json:"exclude_index_files"`
OverrideDefaultIgnores bool `json:"override_default_ignores"`
DailyNotes DailyNotes `json:"daily_notes"`
}
type DailyNotes struct {
Dir string `json:"dir"`
FilenameFormat string `json:"filename_format"`
TemplateName string `json:"template_name"`
} }
type InitializeHandler struct { type InitializeHandler struct {
@ -35,11 +46,15 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
} }
store := store.NewVaultStore( store := store.NewVaultStore(
cmd.VaultName, cmd.Config.VaultName,
cmd.VaultPath, cmd.Config.VaultPath,
cmd.TemplateDirectory, cmd.Config.TemplatesDir,
cmd.ExcludeIndexFiles, cmd.Config.ExcludeIndexFiles,
cmd.OverrideDefaultIgnores) cmd.Config.OverrideDefaultIgnores,
cmd.Config.DailyNotes.Dir,
cmd.Config.DailyNotes.FilenameFormat,
cmd.Config.DailyNotes.TemplateName,
)
err := persistence.InitializeDBContext(store.Config.VaultName()) err := persistence.InitializeDBContext(store.Config.VaultName())
if err != nil { if err != nil {
@ -56,7 +71,7 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
return nil, nil return nil, nil
} }
err = h.idxRebuilder.RebuildIndex(ctx, cmd.VaultPath) err = h.idxRebuilder.RebuildIndex(ctx, cmd.Config.VaultPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }

BIN
dendrite

Binary file not shown.

View file

@ -1,50 +1,61 @@
package persistenceconfig package persistenceconfig
type VaultConfiguration struct { type DailyNotes struct {
name string dir string
path string filenameFormat string
templateDirectory string templateName string
exludeIndexFiles []string }
defaultExcludes []string
func NewDailyNotes(dir, filenameFormat, templateName string) DailyNotes {
return DailyNotes{
dir: dir,
filenameFormat: filenameFormat,
templateName: templateName,
}
}
type VaultConfig struct {
vaultName string
vaultPath string
templatesDir string
excludeIndexFiles []string
overrideDefaultIgnores bool overrideDefaultIgnores bool
dailyNotes DailyNotes
} }
func NewVaultConfiguration( func NewVaultConfiguration(
vaultName, vaultName,
vaultPath, vaultPath,
templateDirectory string, templatesDir string,
excludeIndexFiles []string, excludeIndexFiles []string,
overrideDefaultIgnores bool, overrideDefaultIgnores bool,
) *VaultConfiguration { dailyNotes DailyNotes,
return &VaultConfiguration{ ) *VaultConfig {
name: vaultName, return &VaultConfig{
path: vaultPath, vaultName: vaultName,
templateDirectory: templateDirectory, vaultPath: vaultPath,
exludeIndexFiles: excludeIndexFiles, templatesDir: templatesDir,
defaultExcludes: []string{".git", ".templates"}, dailyNotes: dailyNotes,
} }
} }
func (vc *VaultConfiguration) VaultName() string { func (vc *VaultConfig) VaultName() string {
return vc.name return vc.vaultName
} }
func (vc *VaultConfiguration) VaultPath() string { func (vc *VaultConfig) VaultPath() string {
return vc.path return vc.vaultPath
} }
func (vc *VaultConfiguration) TemplateDirectory() string { func (vc *VaultConfig) TemplateDirectory() string {
return vc.templateDirectory return vc.templatesDir
} }
func (vc *VaultConfiguration) ExcludeIndexFiles() []string { func (vc *VaultConfig) ExcludeIndexFiles() []string {
return vc.exludeIndexFiles defaultIgnores := []string{"index.md", "index"}
}
func (vc *VaultConfiguration) GetExcludeIndexFiles() []string {
defaultIgnores := []string{".git", ".templates"}
if vc.overrideDefaultIgnores { if vc.overrideDefaultIgnores {
return vc.exludeIndexFiles return vc.excludeIndexFiles
} }
return append(defaultIgnores, vc.exludeIndexFiles...) return append(defaultIgnores, vc.excludeIndexFiles...)
} }

View file

@ -7,7 +7,7 @@ import (
) )
type VaultStore struct { type VaultStore struct {
Config *persistenceconfig.VaultConfiguration Config *persistenceconfig.VaultConfig
} }
var vaultStore *VaultStore var vaultStore *VaultStore
@ -18,6 +18,9 @@ func NewVaultStore(
templateDir string, templateDir string,
exludeIndexFiles []string, exludeIndexFiles []string,
overrideDefaultIgnores bool, overrideDefaultIgnores bool,
dailyDir string,
dailyFilenameFormat string,
dailyTemplateName string,
) *VaultStore { ) *VaultStore {
if vaultStore != nil { if vaultStore != nil {
return vaultStore return vaultStore
@ -28,7 +31,7 @@ func NewVaultStore(
templateDir, templateDir,
exludeIndexFiles, exludeIndexFiles,
overrideDefaultIgnores, overrideDefaultIgnores,
)} persistenceconfig.NewDailyNotes(dailyDir, dailyFilenameFormat, dailyTemplateName))}
return vaultStore return vaultStore
} }
@ -39,10 +42,6 @@ func GetVaultStore() *VaultStore {
return vaultStore return vaultStore
} }
func (vs *VaultStore) SetConfig(config persistenceconfig.VaultConfiguration) {
vs.Config = &config
}
func (vs *VaultStore) GetTemplatePath(templateName string) string { func (vs *VaultStore) GetTemplatePath(templateName string) string {
templateName = vs.fileTypeCheck(templateName) templateName = vs.fileTypeCheck(templateName)
return path.Join(vs.Config.TemplateDirectory(), templateName) return path.Join(vs.Config.TemplateDirectory(), templateName)
@ -57,5 +56,5 @@ func (vs *VaultStore) fileTypeCheck(templateName string) string {
} }
func (vs *VaultStore) GetExcludeIndexFiles() []string { func (vs *VaultStore) GetExcludeIndexFiles() []string {
return vs.Config.GetExcludeIndexFiles() return vs.Config.ExcludeIndexFiles()
} }

View file

@ -46,7 +46,7 @@ func NewDBFixture() *DBFixture {
DB: dbContext.DB, DB: dbContext.DB,
DBPath: dbPath, DBPath: dbPath,
TestContext: context.Background(), TestContext: context.Background(),
VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates"), []string{}, false), VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates"), []string{}, false, "", "", ""),
} }
} }