mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
Minor changes
This commit is contained in:
parent
bc3079407d
commit
1539aa587c
2 changed files with 22 additions and 6 deletions
20
cmd/cache.go
20
cmd/cache.go
|
|
@ -13,8 +13,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
withAllHosts bool
|
||||
withAllPorts bool
|
||||
withHosts []string
|
||||
withPorts []int
|
||||
)
|
||||
|
||||
var cacheCmd = &cobra.Command{
|
||||
|
|
@ -34,6 +34,8 @@ var cacheRemoveCmd = &cobra.Command{
|
|||
Short: "Remove a host from a scanned cache list.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
assets := []magellan.RemoteAsset{}
|
||||
|
||||
// add all assets directly from positional args
|
||||
for _, arg := range args {
|
||||
var (
|
||||
port int
|
||||
|
|
@ -46,6 +48,9 @@ var cacheRemoveCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
// convert port to its "proper" type
|
||||
if uri.Port() == "" {
|
||||
uri.Host += ":443"
|
||||
}
|
||||
port, err = strconv.Atoi(uri.Port())
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to convert port to integer type")
|
||||
|
|
@ -54,16 +59,21 @@ var cacheRemoveCmd = &cobra.Command{
|
|||
Host: fmt.Sprintf("%s://%s", uri.Scheme, uri.Hostname()),
|
||||
Port: port,
|
||||
}
|
||||
fmt.Printf("%s:%d\n", asset.Host, asset.Port)
|
||||
assets = append(assets, asset)
|
||||
}
|
||||
|
||||
// add all assets with specified hosts (same host different different ports)
|
||||
for _, host := range withHosts {
|
||||
|
||||
}
|
||||
// add all assets with specified ports (same port different hosts)
|
||||
sqlite.DeleteScannedAssets(cachePath, assets...)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
cacheRemoveCmd.Flags().BoolVar(&withAllHosts, "--all-hosts", false, "Remove all assets with specified hosts")
|
||||
cacheRemoveCmd.Flags().BoolVar(&withAllPorts, "--all-ports", false, "Remove all assets with specified ports")
|
||||
cacheRemoveCmd.Flags().StringSliceVar(&withHosts, "with-hosts", []string{}, "Remove all assets with specified hosts")
|
||||
cacheRemoveCmd.Flags().IntSliceVar(&withPorts, "with-ports", []int{}, "Remove all assets with specified ports")
|
||||
cacheCmd.AddCommand(cacheRemoveCmd)
|
||||
rootCmd.AddCommand(cacheCmd)
|
||||
}
|
||||
|
|
|
|||
8
internal/cache/sqlite/sqlite.go
vendored
8
internal/cache/sqlite/sqlite.go
vendored
|
|
@ -72,7 +72,13 @@ func DeleteScannedAssets(path string, assets ...magellan.RemoteAsset) error {
|
|||
}
|
||||
tx := db.MustBegin()
|
||||
for _, asset := range assets {
|
||||
sql := fmt.Sprintf(`DELETE FROM %s WHERE host=:host AND port=:port;`, TABLE_NAME)
|
||||
if asset.Host == "" && asset.Port <= 0 {
|
||||
continue
|
||||
}
|
||||
sql := fmt.Sprintf(`DELETE FROM %s WHERE port=:port;`, TABLE_NAME)
|
||||
if asset.Host != "" {
|
||||
sql += "AND host=:host"
|
||||
}
|
||||
_, err := tx.NamedExec(sql, &asset)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to execute DELETE transaction: %v\n", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue