Skip to content

Commit

Permalink
Merge dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
qu35t-code committed Jan 27, 2024
2 parents 645c350 + da2b9bc commit 1951106
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions cmd/hosts.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
package cmd

import (
"fmt"
"os"

"github.com/GoToolSharing/htb-cli/config"
"github.com/GoToolSharing/htb-cli/lib/hosts"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var hostsCmd = &cobra.Command{
Use: "hosts",
Short: "Interact with hosts file",
Run: func(cmd *cobra.Command, args []string) {
config.GlobalConfig.Logger.Info("Hosts command executed")
fmt.Println("WIP")
// addParam, err := cmd.Flags().GetString("add")
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }
addParam, err := cmd.Flags().GetString("add")
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}

// deleteParam, err := cmd.Flags().GetString("delete")
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }
deleteParam, err := cmd.Flags().GetString("delete")
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}

// ipParam, err := cmd.Flags().GetString("ip")
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }
ipParam, err := cmd.Flags().GetString("ip")
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}

// if addParam != "" && deleteParam != "" {
// config.GlobalConfig.Logger.Error("Only one parameter is allowed")
// os.Exit(1)
// }
if addParam != "" && deleteParam != "" {
config.GlobalConfig.Logger.Error("Only one parameter is allowed")
os.Exit(1)
}

// if addParam != "" {
// err = hosts.AddEntryToHosts(ipParam, addParam)
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }
// }
if addParam != "" {
err = hosts.AddEntryToHosts(ipParam, addParam)
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
}

// if deleteParam != "" {
// err = hosts.RemoveEntryFromHosts(ipParam, deleteParam)
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }
// }
if deleteParam != "" {
err = hosts.RemoveEntryFromHosts(ipParam, deleteParam)
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
}

config.GlobalConfig.Logger.Info("Exit hosts command correctly")
},
Expand Down

0 comments on commit 1951106

Please sign in to comment.