package main

import (
	"DomainScanners/utils"
	"fmt"
	"github.com/urfave/cli/v2"
	"os"
)

func main() {
	app := &cli.App{
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     "tlds",
				Aliases:  []string{"t"},
				Required: true,
				Usage:    "File containing TLDs to check",
			},
			&cli.IntFlag{
				Name:    "threads",
				Aliases: []string{"w"},
				Usage:   "Number of threads to start",
				Value:   12,
			},
			&cli.BoolFlag{
				Name:    "detailed",
				Aliases: []string{"d"},
				Usage:   "Whether or not to log IP",
				Value:   false,
			},
			&cli.PathFlag{
				Name:    "output",
				Aliases: []string{"o"},
				Usage:   "Where to put the result",
				Value:   "/dev/stdout",
			},
		},
		Args: true,
		Action: func(cCtx *cli.Context) error {
			if cCtx.Args().Len() == 0 {
				msg := "No domains has been passed, please see help with --help"
				utils.Logger.Info().Msg(msg)
				fmt.Println(msg)
			} else {
				return utils.ProcessCli(cCtx)
			}

			return nil
		},
	}

	if err := app.Run(os.Args); err != nil {
		msg := fmt.Sprintf("Failed to parse args: %s", err.Error())
		utils.Logger.Fatal().Msg(msg)
		fmt.Println(msg)
	}
}