-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
option.go
39 lines (33 loc) · 781 Bytes
/
option.go
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
36
37
38
39
package ecrm
import (
"fmt"
"io"
"os"
)
type Option struct {
ScanOnly bool
Scan bool
Delete bool
Force bool
Repository RepositoryName
OutputFile string
Format outputFormat
ScannedFiles []string
}
func (opt *Option) Validate() error {
if len(opt.ScannedFiles) == 0 && !opt.Scan {
return fmt.Errorf("no --scanned-files and --no-scan provided. specify at least one")
}
return nil
}
// NopCloserWriter is a writer that does nothing on Close
type NopCloserWriter struct {
io.Writer
}
func (NopCloserWriter) Close() error { return nil }
func (opt *Option) OutputWriter() (io.WriteCloser, error) {
if opt.OutputFile == "" || opt.OutputFile == "-" {
return NopCloserWriter{os.Stdout}, nil
}
return os.Create(opt.OutputFile)
}