mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Added flag to show cache info with list command and other minor changes
This commit is contained in:
parent
46fc35d4ad
commit
8a2541717d
3 changed files with 24 additions and 9 deletions
14
cmd/list.go
14
cmd/list.go
|
|
@ -12,6 +12,10 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
showCache bool
|
||||
)
|
||||
|
||||
// The `list` command provides an easy way to show what was found
|
||||
// and stored in a cache database from a scan. The data that's stored
|
||||
// is what is consumed by the `collect` command with the --cache flag.
|
||||
|
|
@ -24,6 +28,13 @@ var listCmd = &cobra.Command{
|
|||
" magellan list\n" +
|
||||
" magellan list --cache ./assets.db",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// check if we just want to show cache-related info and exit
|
||||
if showCache {
|
||||
fmt.Printf("cache: %s\n", cachePath)
|
||||
return
|
||||
}
|
||||
|
||||
// load the assets found from scan
|
||||
scannedResults, err := sqlite.GetScannedAssets(cachePath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to get scanned assets")
|
||||
|
|
@ -37,7 +48,7 @@ var listCmd = &cobra.Command{
|
|||
fmt.Printf("%s\n", string(b))
|
||||
} else {
|
||||
for _, r := range scannedResults {
|
||||
fmt.Printf("%s:%d (%s) @ %s\n", r.Host, r.Port, r.Protocol, r.Timestamp.Format(time.UnixDate))
|
||||
fmt.Printf("%s:%d (%s) @%s\n", r.Host, r.Port, r.Protocol, r.Timestamp.Format(time.UnixDate))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -45,5 +56,6 @@ var listCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
listCmd.Flags().StringVar(&format, "format", "", "set the output format (json|default)")
|
||||
listCmd.Flags().BoolVar(&showCache, "cache-info", false, "show cache information and exit")
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue