add .dirmd and other metadata
This commit is contained in:
+27
-13
@@ -10,6 +10,7 @@ import (
|
||||
"git.flo.fo/FLO/dirmd/internal/config"
|
||||
"git.flo.fo/FLO/dirmd/internal/filter"
|
||||
"git.flo.fo/FLO/dirmd/internal/git"
|
||||
"git.flo.fo/FLO/dirmd/internal/instructions"
|
||||
)
|
||||
|
||||
type Entry struct {
|
||||
@@ -18,11 +19,12 @@ type Entry struct {
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Entries []Entry
|
||||
AbsRoot string
|
||||
SingleFile bool
|
||||
OmitTest bool
|
||||
Commit *git.CommitInfo
|
||||
Entries []Entry
|
||||
AbsRoot string
|
||||
SingleFile bool
|
||||
OmitTest bool
|
||||
Commit *git.CommitInfo
|
||||
Instructions string
|
||||
}
|
||||
|
||||
func Run(cfg *config.Config) (*Result, error) {
|
||||
@@ -55,15 +57,19 @@ func processSingleFile(cfg *config.Config) (*Result, error) {
|
||||
return nil, fmt.Errorf("file %s filtered out", cfg.AbsRoot)
|
||||
}
|
||||
|
||||
// For single files, try to get git info from the parent directory
|
||||
commitInfo := git.GetCommitInfo(filepath.Dir(cfg.AbsRoot))
|
||||
var instContent string
|
||||
if cfg.IncludeInstructions {
|
||||
instContent, _ = instructions.Read(filepath.Dir(cfg.AbsRoot))
|
||||
}
|
||||
|
||||
return &Result{
|
||||
Entries: []Entry{{RelPath: filepath.Base(cfg.AbsRoot), Size: info.Size()}},
|
||||
AbsRoot: filepath.Dir(cfg.AbsRoot),
|
||||
SingleFile: true,
|
||||
OmitTest: cfg.OmitTest,
|
||||
Commit: commitInfo,
|
||||
Entries: []Entry{{RelPath: filepath.Base(cfg.AbsRoot), Size: info.Size()}},
|
||||
AbsRoot: filepath.Dir(cfg.AbsRoot),
|
||||
SingleFile: true,
|
||||
OmitTest: cfg.OmitTest,
|
||||
Commit: commitInfo,
|
||||
Instructions: instContent,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -78,9 +84,17 @@ func walkDirectory(cfg *config.Config) (*Result, error) {
|
||||
}
|
||||
|
||||
result := &Result{AbsRoot: cfg.AbsRoot, OmitTest: cfg.OmitTest}
|
||||
|
||||
// Fetch git info for the root directory
|
||||
|
||||
result.Commit = git.GetCommitInfo(cfg.AbsRoot)
|
||||
|
||||
if cfg.IncludeInstructions {
|
||||
instContent, err := instructions.Read(cfg.AbsRoot)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: could not read .dirmd: %v\n", err)
|
||||
} else {
|
||||
result.Instructions = instContent
|
||||
}
|
||||
}
|
||||
|
||||
err := filepath.WalkDir(cfg.AbsRoot, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user