Messing around with native go calls, not using grep/find etc.
I see I can pass dir-arg per demo but when I invoke entries, it's just the current directory without recursion and the DirectoryEntriesOpts{} doesn't give me any option to recurse.
Still wrapping my head around lifecycle 🙂
Am I supposed to use a different arg for passing through the directory with all subdirectories?
My goal was to match all with a pattern, using native dagger/go calls and then I'll upload each of the files using API calls after verifying they match.
Main two issues...
- Recurse?
- If want one func to be the helper method to lookup and return the list of files to iterate through, is it just a []string returned or do I pass a dagger result to another dagger function? I'm guessing I'll find the answer partially in: https://docs.dagger.io/manuals/developer/go/528510/chaining
const PatternDatadogServiceFiles = ".datadog.svcdef.json"
func (m *Daggerverse) GrepDefinitionFiles(ctx context.Context, dirArg *Directory) ([]string, error) {
foundFiles := []string{}
files, err := dirArg.Entries(ctx, dagger.DirectoryEntriesOpts{})
if err != nil {
return foundFiles, err
}
for _, f := range files {
if strings.HasSuffix(f, PatternDatadogServiceFiles) {
foundFiles = append(foundFiles, f)
} else {
foundFiles = append(foundFiles, "NOT MATCHED: "+f)
}
}
return foundFiles, nil
}