Skip to content

Commit

Permalink
Merge pull request #1 from moul/dev/moul/poc
Browse files Browse the repository at this point in the history
feat: POC
  • Loading branch information
moul authored Sep 16, 2019
2 parents 057c1d4 + 764016e commit 387594b
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module moul.io/guilhunize

go 1.13

require gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717 h1:OvXt/p4cdwNl+mwcWMq/AxaKFkhdxcjx+tx+qf4EOvY=
gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717/go.mod h1:cKXr3E0k4aosgycml1b5z33BVV6hai1Kh7uDgFOkbcs=
1 change: 1 addition & 0 deletions guilhunize/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package guilhunize // import "moul.io/guilhunize"
26 changes: 26 additions & 0 deletions guilhunize/guilhunize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package guilhunize

import "strings"

var mapping = [][2]string{
{"refactors", "refractos"},
{"refactos", "refractos"},
{"refactoré", "refractoré"},
{"refactor", "refracto"},
{"refacto", "refracto"},
{"scaleway", "scalaway"},
{"interface", "i-love-interface"},
{"déchiffrement", "désenchiffrement"},
{" chiffrement", " cryptage"},
}

func Guilhunize(input string) string {
// FIXME: refactor to use words instead of regexps
input = strings.ToLower(input)
for _, pair := range mapping {
input = strings.Replace(input, pair[0], pair[1], -1)
}
return input
}

// FIXME: implement "Unguilhunize"
8 changes: 8 additions & 0 deletions guilhunize/guilhunize_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package guilhunize

import "fmt"

func ExampleGuilhunize() {
fmt.Println(Guilhunize("salut, j'aime bien faire des interfaces dans les refactors, surtout lorsqu'il faut faire du chiffrement ou du déchiffrement."))
// Output: salut, j'aime bien faire des i-love-interfaces dans les refractos, surtout lorsqu'il faut faire du cryptage ou du désenchiffrement.
}
31 changes: 29 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
package main

import "fmt"
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"

cli "gopkg.in/urfave/cli.v2"
"moul.io/guilhunize/guilhunize"
)

func main() {
fmt.Println("Hello World!")
app := cli.App{Action: run}
if err := app.Run(os.Args); err != nil {
log.Printf("error: %v\n", err)
os.Exit(1)
}
}

func run(c *cli.Context) error {
message := strings.Join(c.Args().Slice(), " ")
if message == "" {
in, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
message = string(in)
}
out := guilhunize.Guilhunize(message)
fmt.Println(out)
return nil
}
5 changes: 4 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "os"

func Example() {
os.Args = []string{"", "salut, j'aime bien faire des interfaces dans les refactors, surtout lorsqu'il faut faire du chiffrement ou du déchiffrement."}
main()
// Output: Hello World!
// Output: salut, j'aime bien faire des i-love-interfaces dans les refractos, surtout lorsqu'il faut faire du cryptage ou du désenchiffrement.
}

0 comments on commit 387594b

Please sign in to comment.