mirror of
https://github.com/charmbracelet/glow
synced 2024-11-12 23:17:16 +00:00
Search for READMEs case-insensitively & recursively
This commit is contained in:
parent
85cd31dfc4
commit
c5517add19
1 changed files with 24 additions and 8 deletions
32
main.go
32
main.go
|
@ -80,21 +80,37 @@ func readerFromArg(s string) (*Source, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// a valid file or directory:
|
// a directory:
|
||||||
|
if len(s) == 0 {
|
||||||
|
// use the current working dir if no argument was supplied
|
||||||
|
s = "."
|
||||||
|
}
|
||||||
st, err := os.Stat(s)
|
st, err := os.Stat(s)
|
||||||
if len(s) == 0 || (err == nil && st.IsDir()) {
|
if err == nil && st.IsDir() {
|
||||||
for _, v := range readmeNames {
|
var src *Source
|
||||||
n := filepath.Join(s, v)
|
_ = filepath.Walk(s, func(path string, info os.FileInfo, err error) error {
|
||||||
r, err := os.Open(n)
|
for _, v := range readmeNames {
|
||||||
if err == nil {
|
if strings.EqualFold(filepath.Base(path), v) {
|
||||||
u, _ := filepath.Abs(n)
|
r, err := os.Open(path)
|
||||||
return &Source{r, u}, nil
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
u, _ := filepath.Abs(path)
|
||||||
|
src = &Source{r, u}
|
||||||
|
return errors.New("source found")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if src != nil {
|
||||||
|
return src, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("missing markdown source")
|
return nil, errors.New("missing markdown source")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a file:
|
||||||
r, err := os.Open(s)
|
r, err := os.Open(s)
|
||||||
u, _ := filepath.Abs(s)
|
u, _ := filepath.Abs(s)
|
||||||
return &Source{r, u}, err
|
return &Source{r, u}, err
|
||||||
|
|
Loading…
Reference in a new issue