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 {
VaultName string `json:"vaultName"`
VaultPath string `json:"vaultPath"`
TemplateDirectory string `json:"templateDirectory"`
ExcludeIndexFiles []string `json:"excludeIndexFiles"`
OverrideDefaultIgnores bool `json:"overrideDefaultIgnores"`
Config Config `json:"config"`
}
type Config struct {
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 {
@ -35,11 +46,15 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
}
store := store.NewVaultStore(
cmd.VaultName,
cmd.VaultPath,
cmd.TemplateDirectory,
cmd.ExcludeIndexFiles,
cmd.OverrideDefaultIgnores)
cmd.Config.VaultName,
cmd.Config.VaultPath,
cmd.Config.TemplatesDir,
cmd.Config.ExcludeIndexFiles,
cmd.Config.OverrideDefaultIgnores,
cmd.Config.DailyNotes.Dir,
cmd.Config.DailyNotes.FilenameFormat,
cmd.Config.DailyNotes.TemplateName,
)
err := persistence.InitializeDBContext(store.Config.VaultName())
if err != nil {
@ -56,7 +71,7 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
return nil, nil
}
err = h.idxRebuilder.RebuildIndex(ctx, cmd.VaultPath)
err = h.idxRebuilder.RebuildIndex(ctx, cmd.Config.VaultPath)
if err != nil {
return nil, err
}

BIN
dendrite

Binary file not shown.

View file

@ -1,50 +1,61 @@
package persistenceconfig
type VaultConfiguration struct {
name string
path string
templateDirectory string
exludeIndexFiles []string
defaultExcludes []string
type DailyNotes struct {
dir string
filenameFormat string
templateName 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
dailyNotes DailyNotes
}
func NewVaultConfiguration(
vaultName,
vaultPath,
templateDirectory string,
templatesDir string,
excludeIndexFiles []string,
overrideDefaultIgnores bool,
) *VaultConfiguration {
return &VaultConfiguration{
name: vaultName,
path: vaultPath,
templateDirectory: templateDirectory,
exludeIndexFiles: excludeIndexFiles,
defaultExcludes: []string{".git", ".templates"},
dailyNotes DailyNotes,
) *VaultConfig {
return &VaultConfig{
vaultName: vaultName,
vaultPath: vaultPath,
templatesDir: templatesDir,
dailyNotes: dailyNotes,
}
}
func (vc *VaultConfiguration) VaultName() string {
return vc.name
func (vc *VaultConfig) VaultName() string {
return vc.vaultName
}
func (vc *VaultConfiguration) VaultPath() string {
return vc.path
func (vc *VaultConfig) VaultPath() string {
return vc.vaultPath
}
func (vc *VaultConfiguration) TemplateDirectory() string {
return vc.templateDirectory
func (vc *VaultConfig) TemplateDirectory() string {
return vc.templatesDir
}
func (vc *VaultConfiguration) ExcludeIndexFiles() []string {
return vc.exludeIndexFiles
}
func (vc *VaultConfiguration) GetExcludeIndexFiles() []string {
defaultIgnores := []string{".git", ".templates"}
func (vc *VaultConfig) ExcludeIndexFiles() []string {
defaultIgnores := []string{"index.md", "index"}
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 {
Config *persistenceconfig.VaultConfiguration
Config *persistenceconfig.VaultConfig
}
var vaultStore *VaultStore
@ -18,6 +18,9 @@ func NewVaultStore(
templateDir string,
exludeIndexFiles []string,
overrideDefaultIgnores bool,
dailyDir string,
dailyFilenameFormat string,
dailyTemplateName string,
) *VaultStore {
if vaultStore != nil {
return vaultStore
@ -28,7 +31,7 @@ func NewVaultStore(
templateDir,
exludeIndexFiles,
overrideDefaultIgnores,
)}
persistenceconfig.NewDailyNotes(dailyDir, dailyFilenameFormat, dailyTemplateName))}
return vaultStore
}
@ -39,10 +42,6 @@ func GetVaultStore() *VaultStore {
return vaultStore
}
func (vs *VaultStore) SetConfig(config persistenceconfig.VaultConfiguration) {
vs.Config = &config
}
func (vs *VaultStore) GetTemplatePath(templateName string) string {
templateName = vs.fileTypeCheck(templateName)
return path.Join(vs.Config.TemplateDirectory(), templateName)
@ -57,5 +56,5 @@ func (vs *VaultStore) fileTypeCheck(templateName string) 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,
DBPath: dbPath,
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, "", "", ""),
}
}