Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match any file that has readme in it's name #65

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions pkg/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
"time"

c "github.com/theredditbandit/pman/constants"
Expand All @@ -23,7 +24,6 @@ var (
// InitDirs indexes a directory for project directories and writes the data to the DB
func InitDirs(args []string) error {
// the file which identifies a project directory
projIdentifier := "README.md"
if len(args) != 1 {
log.Print("Please provide a directory name")
return ErrDirname
Expand All @@ -36,7 +36,7 @@ func InitDirs(args []string) error {
log.Printf("%s is a file and not a directory \n", dirname)
return ErrIsNotDir
}
projDirs, err := indexDir(dirname, projIdentifier)
projDirs, err := indexDir(dirname)
if err != nil {
log.Print(err)
return ErrIndexDir
Expand Down Expand Up @@ -86,7 +86,8 @@ func InitDirs(args []string) error {
}

// indexDir indexes a directory for project directories
func indexDir(path, identifier string) (map[string]string, error) {
func indexDir(path string) (map[string]string, error) {
identifier := "readme"
projDirs := make(map[string]string)
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand All @@ -98,12 +99,16 @@ func indexDir(path, identifier string) (map[string]string, error) {
projDirs[absPath] = "indexed"
return filepath.SkipDir
}
if !info.IsDir() && info.Name() == identifier {
pname := filepath.Dir(path)
absPath, _ := filepath.Abs(pname)
projDirs[absPath] = "indexed"
return filepath.SkipDir
if !info.IsDir() {
fileName := strings.ToLower(info.Name())
if strings.Contains(fileName, identifier) {
pname := filepath.Dir(path)
absPath, _ := filepath.Abs(pname)
projDirs[absPath] = "indexed"
return filepath.SkipDir
}
}

return nil
})
if err != nil {
Expand Down
Loading