Skip to content

Commit

Permalink
Replace dependencies with stable alternatives (#43)
Browse files Browse the repository at this point in the history
github.com/logrusorgru/aurora -> github.com/fatih/color
github.com/metal3d/go-slugify -> github.com/gosimple/slug

Fix: #42
  • Loading branch information
felipemfp authored Sep 9, 2019
1 parent 617f9a9 commit c8f7a3e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 51 deletions.
47 changes: 20 additions & 27 deletions cmd/sinonimos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"time"

"github.com/briandowns/spinner"
"github.com/fatih/color"
"github.com/felipemfp/sinonimos"
cli "github.com/jawher/mow.cli"
"github.com/logrusorgru/aurora"
)

var name = "sinonimos"
var version = "dev"
var version = "v0.7.0"
var s = spinner.New(spinner.CharSets[14], 100*time.Millisecond)

func main() {
Expand All @@ -26,17 +26,12 @@ func main() {
expressionArr = app.StringsArg("EXPRESSAO", nil, "EXPRESSAO para encontrar sinônimos")
)

log.SetFlags(0)
log.SetOutput(color.Output)

app.Action = func() {
expression := strings.Join(*expressionArr, " ")

// if expression == "" {
// fmt.Fprintln(os.Stderr, "Error: incorrect usage")
// app.PrintHelp()
// os.Exit(1)
// }

log.SetFlags(0)

log.Printf("Buscando sinônimos para \"%s\":\n", expression)
s.Start()
output, err := sinonimos.Find(&sinonimos.FindInput{
Expand All @@ -46,23 +41,22 @@ func main() {
if err != nil {
switch err {
case sinonimos.ErrNotFound:
log.Fatalf(" %s\n", aurora.Red("Desculpa, mas não encontramos nenhum sinônimo"))
log.Fatalf(" %s\n", color.RedString("Desculpa, mas não encontramos nenhum sinônimo"))
default:
log.Fatal(aurora.Red(fmt.Sprintf("\n... falhou (%s)\n", err.Error())))
log.Fatal(color.RedString(fmt.Sprintf("\n... falhou (%s)\n", err.Error())))
}
}

for j, meaning := range output.Meanings {
if meaning.Description != "" {
log.Printf("\n> %s\n", aurora.Colorize(meaning.Description, getColors(j)).Bold())
log.Printf("\n> %s\n", getColorized(j, meaning.Description))
} else {
log.Print("\n> -\n")
}

log.Printf(" %s\n", strings.Join(meaning.Synonyms, ", "))

for _, example := range meaning.Examples {
log.Print(aurora.Gray(fmt.Sprintf(" + %s\n", example)))
log.Print(color.HiWhiteString(fmt.Sprintf(" + %s", example)))
}
}
}
Expand All @@ -72,16 +66,15 @@ func main() {
app.Run(os.Args)
}

func getColors(index int) aurora.Color {
colors := []aurora.Color{
aurora.GreenFg,
aurora.BrownFg,
aurora.BlueFg,
aurora.MagentaFg,
aurora.CyanFg,
}
if index != 0 {
index = index % len(colors)
}
return colors[index]
var colors = []color.Attribute{
color.FgGreen,
color.FgYellow,
color.FgBlue,
color.FgMagenta,
color.FgCyan,
}

func getColorized(index int, str string) string {
c := color.New(colors[index%len(colors)], color.Bold)
return c.Sprint(str)
}
12 changes: 7 additions & 5 deletions find.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"errors"
"fmt"
"net/http"
"strings"

"github.com/gosimple/slug"

"github.com/metal3d/go-slugify"
"github.com/yhat/scrape"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
Expand Down Expand Up @@ -48,7 +50,7 @@ type FindOutput struct {

// Find try to find meanings for an expression on sinonimos.com.br.
func Find(input *FindInput) (*FindOutput, error) {
resp, err := http.Get(fmt.Sprintf("https://www.sinonimos.com.br/%s/", slugify.Marshal(input.Expression)))
resp, err := http.Get(fmt.Sprintf("https://www.sinonimos.com.br/%s/", slug.Make(input.Expression)))
if err != nil {
return nil, err
}
Expand All @@ -68,19 +70,19 @@ func Find(input *FindInput) (*FindOutput, error) {

for j, meaningSection := range meaningSections {
if meaning, ok := scrape.Find(meaningSection, scrape.ByClass("sentido")); ok {
meanings[j].Description = scrape.Text(meaning)
meanings[j].Description = strings.TrimSpace(scrape.Text(meaning))
}

synonyms := scrape.FindAll(meaningSection, synonymMatcher)
meanings[j].Synonyms = make([]string, len(synonyms))
for i, synonym := range synonyms {
meanings[j].Synonyms[i] = scrape.Text(synonym)
meanings[j].Synonyms[i] = strings.TrimSpace(scrape.Text(synonym))
}

examples := scrape.FindAll(meaningSection, scrape.ByClass("exemplo"))
meanings[j].Examples = make([]string, len(examples))
for i, example := range examples {
meanings[j].Examples[i] = scrape.Text(example)
meanings[j].Examples[i] = strings.TrimSpace(scrape.Text(example))
}
}

Expand Down
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ module github.com/felipemfp/sinonimos
go 1.12

require (
github.com/briandowns/spinner v0.0.0-20181018151057-dd69c579ff20
github.com/fatih/color v1.7.0 // indirect
github.com/briandowns/spinner v1.6.1
github.com/fatih/color v1.7.0
github.com/gosimple/slug v1.7.0
github.com/jawher/mow.cli v1.0.4
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/metal3d/go-slugify v0.0.0-20160607203414-7ac2014b2f23
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
github.com/stretchr/testify v1.3.0 // indirect
github.com/yhat/scrape v0.0.0-20161128144610-24b7890b0945
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5 // indirect
golang.org/x/text v0.3.0
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
github.com/briandowns/spinner v0.0.0-20181018151057-dd69c579ff20 h1:kWWOFAhyzkpi4/+L3++mYiZbuxh1TqYkDMHfFjk6ZfE=
github.com/briandowns/spinner v0.0.0-20181018151057-dd69c579ff20/go.mod h1:hw/JEQBIE+c/BLI4aKM8UU8v+ZqrD3h7HC27kKt8JQU=
github.com/briandowns/spinner v1.6.1 h1:LBxHu5WLyVuVEtTD72xegiC7QJGx598LBpo3ywKTapA=
github.com/briandowns/spinner v1.6.1/go.mod h1://Zf9tMcxfRUA36V23M6YGEAv+kECGfvpnLTnb8n4XQ=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/gosimple/slug v1.7.0 h1:BlCZq+BMGn+riOZuRKnm60Fe7+jX9ck6TzzkN1r8TW8=
github.com/gosimple/slug v1.7.0/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
github.com/jawher/mow.cli v1.0.4 h1:hKjm95J7foZ2ngT8tGb15Aq9rj751R7IUDjG+5e3cGA=
github.com/jawher/mow.cli v1.0.4/go.mod h1:5hQj2V8g+qYmLUVWqu4Wuja1pI57M83EChYLVZ0sMKk=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/metal3d/go-slugify v0.0.0-20160607203414-7ac2014b2f23 h1:UhdgaX0bR9ZSz+jRK6cPQLU94Q3KB14ijuHum8YbvBA=
github.com/metal3d/go-slugify v0.0.0-20160607203414-7ac2014b2f23/go.mod h1:sCALRmIiknhX1lHQ8flRsWKMazu5BBjMochEnDupxrk=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/yhat/scrape v0.0.0-20161128144610-24b7890b0945 h1:6Ju8pZBYFTN9FaV/JvNBiIHcsgEmP4z4laciqjfjY8E=
github.com/yhat/scrape v0.0.0-20161128144610-24b7890b0945/go.mod h1:4vRFPPNYllgCacoj+0FoKOjTW68rUhEfqPLiEJaK2w8=
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519 h1:x6rhz8Y9CjbgQkccRGmELH6K+LJj7tOoh3XWeC1yaQM=
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5 h1:x6r4Jo0KNzOOzYd8lbcRsqjuqEASK6ob3auvWYM4/8U=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

0 comments on commit c8f7a3e

Please sign in to comment.