-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
95 lines (74 loc) · 1.93 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"flag"
"fmt"
"os"
"github.com/vodkabears/yaspell/checker"
"github.com/vodkabears/yaspell/config"
"github.com/vodkabears/yaspell/reader"
)
const helpText = `Usage: yaspell [flags] [files ...]
Yaspell checks spelling of large texts with Yandex.Speller API.
Flags:
-opts
Yaspeller options.
Example: -opts=IGNORE_UPPERCASE,IGNORE_DIGITS
IGNORE_UPPERCASE ignores uppercase words
IGNORE_DIGITS ignores words with digits
IGNORE_URLS ignores urls, emails, filenames
FIND_REPEAT_WORDS highlights repetitions of words, consecutive
IGNORE_LATIN ignores latin words
NO_SUGGEST disables suggestions for incorrect words
FLAG_LATIN marks latin words as incorrect
BY_WORDS ignores dictionary context
IGNORE_CAPITALIZATION ignores the incorrect use of UPPERCASE/lowercase letters
IGNORE_ROMAN_NUMERALS ignores roman numerals
-dict
Dictionary file with regexp patterns.
Example: -dict=dict.txt
Regexp syntax: https://golang.org/pkg/regexp/syntax/#hdr-Syntax
dict.txt content:
^lang$
^dict$
-lang
Language to check.
Values: en, ru, uk
Default: ru,en
Example: -lang=en,ru,uk
-format
Text format.
Values: html, plain
Default: plain
Example: -format=html
-version
Prints current version.
`
func main() {
cfg := config.NewConfig()
flag.StringVar(&cfg.Lang, "lang", cfg.Lang, "Language to check")
flag.StringVar(&cfg.Format, "format", cfg.Format, "Text format")
flag.Var(&cfg.Dictionary, "dict", "Dictionary file with regexp patterns")
flag.Var(&cfg.Options, "opts", "Yaspeller options")
flag.Var(&cfg.Version, "version", "Prints current version")
flag.Usage = func() {
fmt.Println(helpText)
}
flag.Parse()
files := flag.Args()
if len(files) == 0 {
flag.Usage()
os.Exit(1)
}
var isError bool
ch := make(chan reader.Chunk)
go reader.Read(ch, files)
for chunk := range ch {
if err := checker.Check(&chunk, cfg); err != nil {
isError = true
fmt.Println(err)
}
}
if isError {
os.Exit(1)
}
}