mirror of
https://github.com/wahyd4/node-prune.git
synced 2026-08-09 05:06:18 +10:00
add options
This commit is contained in:
@@ -22,15 +22,13 @@ func main() {
|
||||
|
||||
start := time.Now()
|
||||
|
||||
if dir == "" {
|
||||
dir = "node_modules"
|
||||
}
|
||||
|
||||
if *debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
stats, err := prune.Prune(dir)
|
||||
p := prune.New(prune.WithDir(dir))
|
||||
|
||||
stats, err := p.Prune()
|
||||
if err != nil {
|
||||
log.Fatalf("error: %s", err)
|
||||
}
|
||||
|
||||
@@ -22,9 +22,23 @@ type Pruner struct {
|
||||
Log log.Interface
|
||||
}
|
||||
|
||||
// Prune dir of unnecessary files.
|
||||
func Prune(dir string) (*Stats, error) {
|
||||
return Pruner{dir, log.Log}.Prune()
|
||||
// Option function.
|
||||
type Option func(*Pruner)
|
||||
|
||||
// New with the given options.
|
||||
func New(options ...Option) *Pruner {
|
||||
v := &Pruner{Dir: "node_modules", Log: log.Log}
|
||||
for _, o := range options {
|
||||
o(v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// WithDir option.
|
||||
func WithDir(s string) Option {
|
||||
return func(v *Pruner) {
|
||||
v.Dir = s
|
||||
}
|
||||
}
|
||||
|
||||
// Prune performs the pruning.
|
||||
|
||||
Reference in New Issue
Block a user