Allow Optional Args With Extract

This commit is contained in:
2026-04-21 19:04:58 +02:00
parent 8bfcebc6dc
commit b690135057
3 changed files with 34 additions and 20 deletions
+2 -1
View File
@@ -300,7 +300,8 @@ func runExtract(ctx context) error {
return err return err
} }
result, err := pipeline.Extract(p) files := ctx.args[1:]
result, err := pipeline.Extract(p, files...)
if err != nil { if err != nil {
return err return err
} }
+32 -19
View File
@@ -24,29 +24,37 @@ type ExtractResult struct {
Skipped int Skipped int
} }
func Extract(p *project.Project) (ExtractResult, error) { func Extract(p *project.Project, files ...string) (ExtractResult, error) {
modulePath := filepath.Join(p.BuildDir(), p.Config.Module.ResRef+".mod")
input, err := os.Open(modulePath)
if err != nil {
return ExtractResult{}, fmt.Errorf("open module archive: %w", err)
}
defer input.Close()
archive, err := erf.Read(input)
if err != nil {
return ExtractResult{}, fmt.Errorf("read module archive: %w", err)
}
var result ExtractResult var result ExtractResult
result.ModulePath = modulePath
var failures []error var failures []error
desired := map[string]struct{}{} desired := map[string]struct{}{}
written, overwritten, skipped, errs := extractArchiveResources(p, archive, desired) allowed := make(map[string]bool)
result.Written += written for _, f := range files {
result.Overwritten += overwritten allowed[f] = true
result.Skipped += skipped }
failures = append(failures, errs...)
shouldExtractMod := len(allowed) == 0 || allowed[p.Config.Module.ResRef+".mod"]
if shouldExtractMod {
modulePath := filepath.Join(p.BuildDir(), p.Config.Module.ResRef+".mod")
input, err := os.Open(modulePath)
if err != nil {
return ExtractResult{}, fmt.Errorf("open module archive: %w", err)
}
defer input.Close()
archive, err := erf.Read(input)
if err != nil {
return ExtractResult{}, fmt.Errorf("read module archive: %w", err)
}
result.ModulePath = modulePath
written, overwritten, skipped, errs := extractArchiveResources(p, archive, desired)
result.Written += written
result.Overwritten += overwritten
result.Skipped += skipped
failures = append(failures, errs...)
}
hakPaths, err := filepath.Glob(filepath.Join(p.BuildDir(), "*.hak")) hakPaths, err := filepath.Glob(filepath.Join(p.BuildDir(), "*.hak"))
if err != nil { if err != nil {
@@ -54,6 +62,11 @@ func Extract(p *project.Project) (ExtractResult, error) {
} }
slices.Sort(hakPaths) slices.Sort(hakPaths)
for _, hakPath := range hakPaths { for _, hakPath := range hakPaths {
filename := filepath.Base(hakPath)
if len(allowed) > 0 && !allowed[filename] {
continue
}
input, err := os.Open(hakPath) input, err := os.Open(hakPath)
if err != nil { if err != nil {
failures = append(failures, fmt.Errorf("open hak archive %s: %w", hakPath, err)) failures = append(failures, fmt.Errorf("open hak archive %s: %w", hakPath, err))
BIN
View File
Binary file not shown.