Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ class: sifter
name: census_2010

params:
census: ../data/census_2010_byzip.json
date: "2010-01-01"
schema: ../covid19_datadictionary/gdcdictionary/schemas/
census:
type: file
default: ../data/census_2010_byzip.json
date:
default: "2010-01-01"
schema:
type: path
default: ../covid19_datadictionary/gdcdictionary/schemas/

inputs:
censusData:
jsonLoad:
input: "{{params.census}}"

outputs:


pipelines:
transform:
- from: censusData
Expand Down
9 changes: 7 additions & 2 deletions cmd/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var outDir string = ""
var paramsFile string = ""
var verbose bool = false
var cmdParams map[string]string
var captureDir string = ""
var captureLimit int = 10

// Cmd is the declaration of the command line
var Cmd = &cobra.Command{
Expand Down Expand Up @@ -46,11 +48,11 @@ var Cmd = &cobra.Command{
}
pb := playbook.Playbook{}
playbook.ParseBytes(yaml, "./playbook.yaml", &pb)
if err := Execute(pb, "./", "./", outDir, params); err != nil {
if err := Execute(pb, "./", "./", outDir, params, captureDir, captureLimit); err != nil {
return err
}
} else {
if err := ExecuteFile(playFile, "./", outDir, params); err != nil {
if err := ExecuteFile(playFile, "./", outDir, params, captureDir, captureLimit); err != nil {
return err
}
}
Expand All @@ -65,4 +67,7 @@ func init() {
flags.BoolVarP(&verbose, "verbose", "v", verbose, "Verbose logging")
flags.StringToStringVarP(&cmdParams, "param", "p", cmdParams, "Parameter variable")
flags.StringVarP(&paramsFile, "params-file", "f", paramsFile, "Parameter file")
flags.StringVarP(&captureDir, "capture-dir", "d", "", "Directory for capture files (default: None)")
flags.IntVarP(&captureLimit, "capture-limit", "l", 10, "Max records to capture per step (0 = unlimited)")
flags.StringVarP(&outDir, "output", "o", outDir, "Output directory for playbook results (default: current directory or value specified in playbook)")
Comment on lines +70 to +72

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New CLI options (--capture-dir, --capture-limit) add behavior that isn’t covered by the existing command-line integration test (test/command_line_test.go runs sifter run without flags). Consider adding a test case that enables capture and asserts that the expected .ndjson files are created (and respect the limit), to prevent regressions.

Copilot uses AI. Check for mistakes.
}
26 changes: 22 additions & 4 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/bmeg/sifter/task"
)

func ExecuteFile(playFile string, workDir string, outDir string, inputs map[string]string) error {
func ExecuteFile(playFile string, workDir string, outDir string, inputs map[string]string, debugDir string, debugLimit int) error {
logger.Info("Starting", "playFile", playFile)
pb := playbook.Playbook{}
if err := playbook.ParseFile(playFile, &pb); err != nil {
Expand All @@ -19,10 +19,10 @@ func ExecuteFile(playFile string, workDir string, outDir string, inputs map[stri
a, _ := filepath.Abs(playFile)
baseDir := filepath.Dir(a)
logger.Debug("parsed file", "baseDir", baseDir, "playbook", pb)
return Execute(pb, baseDir, workDir, outDir, inputs)
return Execute(pb, baseDir, workDir, outDir, inputs, debugDir, debugLimit)
}

func Execute(pb playbook.Playbook, baseDir string, workDir string, outDir string, params map[string]string) error {
func Execute(pb playbook.Playbook, baseDir string, workDir string, outDir string, params map[string]string, debugDir string, debugLimit int) error {

if outDir == "" {
outDir = pb.GetDefaultOutDir()
Expand All @@ -32,13 +32,31 @@ func Execute(pb playbook.Playbook, baseDir string, workDir string, outDir string
os.MkdirAll(outDir, 0777)
}

// Setup debug capture directory if enabled
// Enable if: user explicitly set dir, OR user changed limit from default
enableDebug := debugDir != "" || (debugLimit != 10)
if enableDebug {
if debugDir == "" {
debugDir = filepath.Join(workDir, "debug-capture")
} else if !filepath.IsAbs(debugDir) {
debugDir = filepath.Join(workDir, debugDir)
}
if _, err := os.Stat(debugDir); os.IsNotExist(err) {
if err := os.MkdirAll(debugDir, 0777); err != nil {
logger.Error("Failed to create debug directory", "error", err)
return err
}
}

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In debug mode, os.Stat(debugDir) errors other than IsNotExist (e.g., permission issues) are ignored, and a non-directory existing path isn’t validated. This can lead to capture being “enabled” but all file creation failing later. Consider handling any Stat error and verifying debugDir is a directory before continuing.

Copilot uses AI. Check for mistakes.
logger.Info("Debug capture enabled", "dir", debugDir, "limit", debugLimit)
}

nInputs, err := pb.PrepConfig(params, workDir)
if err != nil {
return err
}
logger.Debug("Running", "outDir", outDir)

t := task.NewTask(pb.Name, baseDir, workDir, outDir, nInputs)
err = pb.Execute(t)
err = pb.Execute(t, debugDir, debugLimit)
return err
}
14 changes: 14 additions & 0 deletions extractors/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ func (ex *Extractor) Start(t task.RuntimeTask) (chan map[string]interface{}, err
return nil, fmt.Errorf(("Extractor not defined"))
}

func (ex *Extractor) GetType() reflect.Type {
v := reflect.ValueOf(ex).Elem()
for i := 0; i < v.NumField(); i++ {
f := v.Field(i)
x := f.Interface()
if _, ok := x.(Source); ok {
if !f.IsNil() {
return f.Type()
}
}
}
return nil
}

func (ex *Extractor) GetRequiredParams() []config.ParamRequest {
out := []config.ParamRequest{}
v := reflect.ValueOf(ex).Elem()
Expand Down
Loading
Loading