-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathopt_progress.go
More file actions
35 lines (31 loc) · 1017 Bytes
/
opt_progress.go
File metadata and controls
35 lines (31 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package nmap
import (
"errors"
"fmt"
"time"
)
// WithProgress enables live progress updates by parsing <taskprogress> elements
// from the XML stream. The interval controls nmap's --stats-every option.
//
// NOTE: progress updates require XML output on stdout. Using ToFile disables
// the live progress stream.
func WithProgress(interval time.Duration, handler func(TaskProgress)) Option {
return func(s *Scanner) error {
if handler == nil {
return errors.New("progress handler must not be nil")
}
if s.toFile != nil {
return errors.New("progress updates require XML on stdout; do not use WithProgress with ToFile")
}
if !s.interactive {
return errors.New("progress updates require interactive terminal; cannot use WithProgress in non-interactive mode")
}
formatted, err := formatNmapDuration(interval)
if err != nil {
return fmt.Errorf("format progress interval: %w", err)
}
s.args = append(s.args, "--stats-every", formatted)
s.progressHandler = handler
return nil
}
}