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:
2025-10-20 22:44:40 +05:00
parent c3a513f92c
commit 9210448f16
3 changed files with 83 additions and 0 deletions

View File

@@ -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
}