本文整理汇总了Golang中mig/ninja/mig/client.Client.GetCommand方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.GetCommand方法的具体用法?Golang Client.GetCommand怎么用?Golang Client.GetCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig/ninja/mig/client.Client
的用法示例。
在下文中一共展示了Client.GetCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: commandReader
// commandReader retrieves an command from the API using its numerical ID
// and enters prompt mode to analyze it
func commandReader(input string, cli client.Client) (err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("commandReader() -> %v", e)
}
}()
inputArr := strings.Split(input, " ")
if len(inputArr) < 2 {
panic("wrong order format. must be 'command <commandid>'")
}
cmdid, err := strconv.ParseFloat(inputArr[1], 64)
if err != nil {
panic(err)
}
cmd, err := cli.GetCommand(cmdid)
if err != nil {
panic(err)
}
fmt.Println("Entering command reader mode. Type \x1b[32;1mexit\x1b[0m or press \x1b[32;1mctrl+d\x1b[0m to leave. \x1b[32;1mhelp\x1b[0m may help.")
fmt.Printf("Command %.0f ran on agent '%s' based on action '%s'\n",
cmd.ID, cmd.Agent.Name, cmd.Action.Name)
prompt := fmt.Sprintf("\x1b[36;1mcommand %d>\x1b[0m ", uint64(cmdid)%1000)
for {
// completion
var symbols = []string{"exit", "help", "json", "found", "pretty", "r", "results"}
readline.Completer = func(query, ctx string) []string {
var res []string
for _, sym := range symbols {
if strings.HasPrefix(sym, query) {
res = append(res, sym)
}
}
return res
}
input, err := readline.String(prompt)
if err == io.EOF {
break
}
if err != nil {
fmt.Println("error: ", err)
break
}
orders := strings.Split(strings.TrimSpace(input), " ")
switch orders[0] {
case "exit":
fmt.Printf("exit\n")
goto exit
case "help":
fmt.Printf(`The following orders are available:
exit exit this mode
help show this help
json show the json of the command
r refresh the command (get latest version from upstream)
results <found> print the results. if "found" is set, only print results that have at least one found
`)
case "json":
var cjson []byte
cjson, err = json.MarshalIndent(cmd, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("%s\n", cjson)
case "r":
cmd, err = cli.GetCommand(cmdid)
if err != nil {
panic(err)
}
fmt.Println("Reload succeeded")
case "results":
found := false
if len(orders) > 1 {
if orders[1] == "found" {
found = true
} else {
fmt.Printf("Unknown option '%s'\n", orders[1])
}
}
err = client.PrintCommandResults(cmd, found, false)
if err != nil {
panic(err)
}
case "":
break
default:
fmt.Printf("Unknown order '%s'. You are in command reader mode. Try `help`.\n", orders[0])
}
readline.AddHistory(input)
}
exit:
fmt.Printf("\n")
return
}