-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (59 loc) · 1.81 KB
/
main.go
File metadata and controls
69 lines (59 loc) · 1.81 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
package main
import (
"flag"
"fmt"
"log"
"os"
pprof "runtime/pprof"
"github.com/runik-3/builder/dict"
wikibot "github.com/runik-3/builder/wikiBot"
)
func main() {
entryLimit := flag.Int("l", 10000, "The maximum number of entries in the dictionary.")
depth := flag.Int("d", 1, "How many sentences make up each definition.")
name := flag.String("n", "", "The file name of the generated dictionary (extension added automatically).")
output := flag.String("o", "", "The output directory where generated dictionary will be written. If not passed in, no file will be generated (preferred behaviour when calling builder as module).")
format := flag.String("f", "json", "Format of the output file.")
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
options := dict.GeneratorOptions{
Name: *name,
Output: *output,
Format: *format,
Depth: *depth,
EntryLimit: *entryLimit,
ProgressHook: printProgress,
}
args := flag.Args()
if len(args) < 2 {
log.Fatal("You must provide at least one argument.")
}
command := args[0]
switch command {
case "generate":
wikiUrl := args[1]
_, err := dict.BuildDictionary(wikiUrl, options)
if err != nil {
log.Fatalf("There was an error building the dictionary:\n%s", err.Error())
}
case "info":
wikiUrl := args[1]
err := wikibot.PrintWikiDetails(wikiUrl)
if err != nil {
log.Fatalf("There was an error retrieving wiki info:\n%s", err.Error())
}
default:
log.Fatalf("%s is not a valid command. See help for more options.", args[0])
}
}
func printProgress(current int, total int) {
fmt.Printf("%d/%d articles processed\n", current, total)
}