summaryrefslogtreecommitdiffstats
path: root/cmd/crawl.go
blob: 3587eb03f32963d71c59dbd3c1ba8c8f0f9cfbcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

var crawlCmd = &cobra.Command{
	Use:   "crawl [domain]",
	Short: "Crawl domain",
	Long:  `Resolves a domain using httpx and crawls it using katana. Returns discovered links as plain text, one per line, streamed in real-time. Supports both http:// and https:// URLs.`,
	Args:  cobra.ExactArgs(1),
	RunE:  runCrawl,
}

func init() {
	rootCmd.AddCommand(crawlCmd)
}

func runCrawl(cmd *cobra.Command, args []string) error {
	c, err := newUnauthenticatedClient()
	if err != nil {
		return err
	}

	err = c.CrawlDomain(args[0], func(line string) error {
		fmt.Println(line)
		return nil
	})

	if err != nil {
		return err
	}

	return nil
}