mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 14:58:00 -05:00
36 lines
757 B
Go
36 lines
757 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/kopia/kopia/snapshot"
|
|
)
|
|
|
|
func policyTargets(pmgr *snapshot.PolicyManager, globalFlag *bool, targetsFlag *[]string) ([]snapshot.SourceInfo, error) {
|
|
if *globalFlag == (len(*targetsFlag) > 0) {
|
|
return nil, fmt.Errorf("must pass either '--global' or a list of path targets")
|
|
}
|
|
|
|
if *globalFlag {
|
|
return []snapshot.SourceInfo{
|
|
snapshot.GlobalPolicySourceInfo,
|
|
}, nil
|
|
}
|
|
|
|
var res []snapshot.SourceInfo
|
|
for _, ts := range *targetsFlag {
|
|
if t, err := pmgr.GetPolicyByID(ts); err == nil {
|
|
res = append(res, t.Target())
|
|
continue
|
|
}
|
|
target, err := snapshot.ParseSourceInfo(ts, getHostName(), getUserName())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res = append(res, target)
|
|
}
|
|
|
|
return res, nil
|
|
}
|