[cmd] add 'list' command
This commit is contained in:
parent
2943c40790
commit
9254c3f85b
2 changed files with 51 additions and 0 deletions
45
commands/list.go
Normal file
45
commands/list.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
Copyright (c) 2018 Rasmus Moorats (neonsea)
|
||||
|
||||
This file is part of iopshell.
|
||||
|
||||
iopshell is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
iopshell is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with iopshell. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"gitlab.com/neonsea/iopshell/internal/cmd"
|
||||
"gitlab.com/neonsea/iopshell/internal/setting"
|
||||
)
|
||||
|
||||
var list = cmd.Command{
|
||||
Name: "list",
|
||||
UsageText: "list [path]",
|
||||
Description: "Lists available methods in [path]. If none provided, lists all of them",
|
||||
Action: listRun,
|
||||
MaxArg: 2,
|
||||
}
|
||||
|
||||
func listRun(param []string) {
|
||||
if len(param) == 1 {
|
||||
setting.Vars.Conn.List(param[0])
|
||||
} else {
|
||||
setting.Vars.Conn.List("*")
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
list.Register()
|
||||
}
|
|
@ -49,6 +49,12 @@ func (c *Connection) Call(path, method string, message map[string]interface{}) {
|
|||
c.Send(request)
|
||||
}
|
||||
|
||||
// List available namespaces
|
||||
func (c *Connection) List(namespace string) {
|
||||
request := c.genUbusRequest("list", namespace, "", make(map[string]interface{}))
|
||||
c.Send(request)
|
||||
}
|
||||
|
||||
func resultToStr(r int) string {
|
||||
switch r {
|
||||
case 0:
|
||||
|
|
Loading…
Reference in a new issue