-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (48 loc) · 868 Bytes
/
main.go
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
package main
import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
)
type Context struct {
Url url.URL
Dir string
Depth int
Cache map[string]struct{}
}
func main() {
args := os.Args[1:]
if len(args) < 2 {
fmt.Println("Usage: sourcerer [name] ...[urls]")
return
}
cwd, err := os.Getwd()
if err != nil {
Error(0, "Failed to get current path", err)
return
}
name := args[0]
dir := filepath.Join(cwd, name)
if err := os.Mkdir(dir, os.ModePerm); err != nil {
Error(0, "Failed to create output directory", err)
return
}
for _, arg := range args {
if strings.HasPrefix(arg, "http") {
url, err := url.Parse(arg)
if err != nil {
fmt.Println("Error parsing url:", err)
return
}
ctx := Context{
Dir: dir,
Url: *url,
Cache: make(map[string]struct{}),
Depth: 0,
}
fromUrl(ctx)
}
}
}