CLI flags

This commit is contained in:
bakape 2018-12-09 21:54:16 +02:00
parent 6434ea655c
commit a60b5861f6
5 changed files with 42 additions and 11 deletions

View File

@ -1,18 +1,31 @@
package main
import (
"flag"
"fmt"
"log"
"net/http"
"strings"
"github.com/bakape/captchouli"
)
var defaultTags = [...]string{
"patchouli_knowledge", "cirno", "hakurei_reimu", "kirisame_marisa",
"konpaku_youmu", "kaname_madoka", "sakura_kyouko", "akemi_homura", ":>",
"patchouli_knowledge", "patchouli_knowledge", "hakurei_reimu", "kirisame_marisa",
"konpaku_youmu", ":>",
}
func main() {
address := flag.String("a", ":8512", "address for server to listen on")
explicit := flag.Bool("e", false,
"allow explicit rating images in the pool")
tags := flag.String("t", strings.Join(defaultTags[:], ","),
`Comma-separated list of tags to use in the pool. At least 3 required
Note that only tags that are detectable from the characters face should e used.
`)
flag.Parse()
var s *captchouli.Service
err := func() (err error) {
err = captchouli.Open()
@ -20,9 +33,19 @@ func main() {
return
}
s, err = captchouli.NewService(captchouli.Options{
Tags: defaultTags[:],
})
tags := strings.Split(*tags, ",")
if len(tags) < 3 {
return fmt.Errorf("not enough tags provided")
}
opts := captchouli.Options{
Tags: tags,
}
if *explicit {
opts.Explicitness = []captchouli.Rating{captchouli.Safe,
captchouli.Questionable, captchouli.Explicit}
}
s, err = captchouli.NewService(opts)
return
}()
if err != nil {
@ -30,5 +53,6 @@ func main() {
}
defer captchouli.Close()
log.Println(http.ListenAndServe(":8003", s.Router()))
log.Println("listening on " + *address)
log.Println(http.ListenAndServe(*address, s.Router()))
}

6
go.mod
View File

@ -1,8 +1,8 @@
module github.com/bakape/captchouli
require (
github.com/Masterminds/squirrel v0.0.0-20181126160726-407c0f9b9512
github.com/bakape/boorufetch v0.0.0-20181202192329-4e9f999d98ed
github.com/Masterminds/squirrel v0.0.0-20181204161840-e5bf00f96d4a
github.com/bakape/boorufetch v0.0.0-20181209175127-a461c8aa4884
github.com/dimfeld/httptreemux v5.0.1+incompatible
github.com/julienschmidt/httprouter v1.2.0
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
@ -10,5 +10,5 @@ require (
github.com/mattn/go-sqlite3 v1.10.0
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/quicktemplate v1.0.0
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc
golang.org/x/net v0.0.0-20181207154023-610586996380
)

6
go.sum
View File

@ -2,8 +2,12 @@ github.com/Masterminds/squirrel v0.0.0-20181030160206-3ba160b0147f h1:8JBQSKzsc4
github.com/Masterminds/squirrel v0.0.0-20181030160206-3ba160b0147f/go.mod h1:xnKTFzjGUiZtiOagBsfnvomW+nJg2usB1ZpordQWqNM=
github.com/Masterminds/squirrel v0.0.0-20181126160726-407c0f9b9512 h1:2nyS7BEYZjIS3jD1UsnRYiOz1E/yNUACPYchgkUFWy0=
github.com/Masterminds/squirrel v0.0.0-20181126160726-407c0f9b9512/go.mod h1:xnKTFzjGUiZtiOagBsfnvomW+nJg2usB1ZpordQWqNM=
github.com/Masterminds/squirrel v0.0.0-20181204161840-e5bf00f96d4a h1:pMmt05odIWMlrx89uWavde2DDX8SXzaYnbGW+knFeU0=
github.com/Masterminds/squirrel v0.0.0-20181204161840-e5bf00f96d4a/go.mod h1:xnKTFzjGUiZtiOagBsfnvomW+nJg2usB1ZpordQWqNM=
github.com/bakape/boorufetch v0.0.0-20181202192329-4e9f999d98ed h1:wH6FmeLtKtKIULVlpNz7xMf/giDSPSa0diD7S9zP/VI=
github.com/bakape/boorufetch v0.0.0-20181202192329-4e9f999d98ed/go.mod h1:5w+CugEba6no6uHTyaDMjZeYq5Xir8C6A9xtZr/wsbs=
github.com/bakape/boorufetch v0.0.0-20181209175127-a461c8aa4884 h1:osPsMSLF5KD9+IWUMv9+YpO+AwjqFDL7CljMHy/Dua8=
github.com/bakape/boorufetch v0.0.0-20181209175127-a461c8aa4884/go.mod h1:5w+CugEba6no6uHTyaDMjZeYq5Xir8C6A9xtZr/wsbs=
github.com/dimfeld/httptreemux v5.0.1+incompatible h1:Qj3gVcDNoOthBAqftuD596rm4wg/adLLz5xh5CmpiCA=
github.com/dimfeld/httptreemux v5.0.1+incompatible/go.mod h1:rbUlSV+CCpv/SuqUTP/8Bk2O3LyUV436/yaRGkhP6Z0=
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
@ -22,3 +26,5 @@ golang.org/x/net v0.0.0-20181108082009-03003ca0c849 h1:FSqE2GGG7wzsYUsWiQ8MZrvEd
golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc h1:a3CU5tJYVj92DY2LaA1kUkrsqD5/3mLDhx2NcNqyW+0=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181207154023-610586996380 h1:zPQexyRtNYBc7bcHmehl1dH6TB3qn8zytv8cBGLDNY0=
golang.org/x/net v0.0.0-20181207154023-610586996380/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

View File

@ -1,4 +1,4 @@
package common
package test_utils
import (
"io/ioutil"

View File

@ -6,6 +6,7 @@ import (
"testing"
"github.com/bakape/captchouli/common"
"github.com/bakape/captchouli/test_utils"
)
func TestThumbnailing(t *testing.T) {
@ -30,7 +31,7 @@ func TestThumbnailing(t *testing.T) {
if err != nil {
t.Fatal(err)
}
common.WriteSample(t, fmt.Sprintf("sample_%s_thumb.jpg", c.ext),
test_utils.WriteSample(t, fmt.Sprintf("sample_%s_thumb.jpg", c.ext),
thumb)
})
}