Refactor table management to use a dedicated API and improve command handling.
This commit is contained in:
37
internal/command/command.go
Normal file
37
internal/command/command.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type NFT interface {
|
||||
Run(arg ...string) error
|
||||
}
|
||||
|
||||
type execNFT struct {
|
||||
nftPath string
|
||||
}
|
||||
|
||||
func New(path string) (NFT, error) {
|
||||
if err := checkingNFT(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &execNFT{
|
||||
nftPath: path,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *execNFT) Run(arg ...string) error {
|
||||
cmd := exec.Command(r.nftPath, arg...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
if len(out) > 0 {
|
||||
return errors.New(string(out))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user