Add Version method to NFT interface and implementation
Include `RunWithOutput` support in the command package and introduce version parsing logic, enabling retrieval of the nftables version and options.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
type NFT interface {
|
||||
Run(arg ...string) error
|
||||
RunWithOutput(arg ...string) (string, error)
|
||||
}
|
||||
|
||||
type execNFT struct {
|
||||
@@ -35,3 +36,15 @@ func (r *execNFT) Run(arg ...string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *execNFT) RunWithOutput(arg ...string) (string, error) {
|
||||
cmd := exec.Command(r.nftPath, arg...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
if len(out) > 0 {
|
||||
return string(out), err
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user