-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (68 loc) · 1.79 KB
/
main.go
File metadata and controls
75 lines (68 loc) · 1.79 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"github.com/urfave/cli/v3"
"github.com/jacobbrewer1/trackify/ipaddress"
"github.com/jacobbrewer1/trackify/username"
)
func coreContext() (context.Context, context.CancelFunc) {
return signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
}
func main() {
cmd := &cli.Command{
Commands: []*cli.Command{
{
Name: "username",
Usage: "Track online accounts for a given username",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "target",
Aliases: []string{"t"},
Usage: "Specify a target platform to search (can be specified multiple times). If not specified, all platforms will be searched.",
},
},
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
args := cmd.Args()
if args.Len() < 1 {
return nil, cli.Exit("at least one username is required", 1)
}
return ctx, nil
},
Action: func(ctx context.Context, cmd *cli.Command) error {
return username.TrackUsernames(
ctx,
cmd.Args().Slice(),
cmd.StringSlice("target"),
)
},
},
{
Name: "ip",
Usage: "Track given IP addresses",
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
args := cmd.Args()
if args.Len() < 1 {
return nil, cli.Exit("at least one IP Address is required", 1)
}
return ctx, nil
},
Action: func(ctx context.Context, cmd *cli.Command) error {
return ipaddress.TrackIPAddresses(
ctx,
cmd.Args().Slice(),
)
},
},
},
}
ctx, cancel := coreContext()
defer cancel()
if err := cmd.Run(ctx, os.Args); err != nil {
cancel()
log.Fatal(err) // nolint:gocritic // Calling cancel() before exiting on the line above
}
}