Adding system interaction functions
For now we can run a service commad
This commit is contained in:
parent
e5ebf1ce11
commit
2fe742f4f8
|
@ -0,0 +1,41 @@
|
||||||
|
package owrt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SysAction is the result of an UCI action output and return code
|
||||||
|
type SysAction struct {
|
||||||
|
*CommandResult
|
||||||
|
Command string
|
||||||
|
}
|
||||||
|
|
||||||
|
// System "Object", an inteface with openwrt system
|
||||||
|
type System struct {
|
||||||
|
exec Executor
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSystem return an OpenWRT System instance to interact with UCI
|
||||||
|
func NewSystem() *System {
|
||||||
|
exec := &localExecutor{}
|
||||||
|
return &System{exec}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSystemWithExecutor returns a System Instance an gives you the ability to provide
|
||||||
|
// a different command executor than the default one.
|
||||||
|
func NewSystemWithExecutor(exec Executor) *System {
|
||||||
|
return &System{exec}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sysRun, private method to run the UCI command
|
||||||
|
func (s *System) sysRun(param ...string) *SysAction {
|
||||||
|
cmd := param[0]
|
||||||
|
res := s.exec.Run(cmd, param...)
|
||||||
|
return &SysAction{res, fmt.Sprintf("%s %s", cmd, param)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service implementation of "service" command
|
||||||
|
func (s *System) Service(name string, action string) *SysAction {
|
||||||
|
cmd := fmt.Sprintf("/etc/init.d/%s ", name)
|
||||||
|
return s.sysRun(cmd, action)
|
||||||
|
}
|
Loading…
Reference in New Issue