mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Added format flag to convery output to JSON and slighly changed scanning logic
This commit is contained in:
parent
a2b841b401
commit
b3ba75ea9a
3 changed files with 52 additions and 26 deletions
13
cmd/list.go
13
cmd/list.go
|
|
@ -1,7 +1,9 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/OpenCHAMI/magellan/internal/db/sqlite"
|
||||
|
||||
|
|
@ -17,12 +19,19 @@ var listCmd = &cobra.Command{
|
|||
if err != nil {
|
||||
logrus.Errorf("failed toget probe results: %v\n", err)
|
||||
}
|
||||
for _, r := range probeResults {
|
||||
fmt.Printf("%s:%d (%s)\n", r.Host, r.Port, r.Protocol)
|
||||
format = strings.ToLower(format)
|
||||
if format == "json" {
|
||||
b, _ := json.Marshal(probeResults)
|
||||
fmt.Printf("%s\n", string(b))
|
||||
} else {
|
||||
for _, r := range probeResults {
|
||||
fmt.Printf("%s:%d (%s)\n", r.Host, r.Port, r.Protocol)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
listCmd.Flags().StringVar(&format, "format", "", "set the output format")
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue