From 0842218d6c3c0ead4b78b308bc3af6f2e3a85ff7 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Thu, 22 Aug 2019 07:34:39 +0200 Subject: [PATCH] feat: initial version --- .circleci/config.yml | 53 +++++++++++++++++++++++++++ .dockerignore | 35 ++++++++++++++++++ .editorconfig | 63 ++++++++++++++++++++++++++++++++ .gitattributes | 11 ++++++ .gitignore | 24 ++++++++++++ .golangci.yml | 34 +++++++++++++++++ .goreleaser.yml | 41 +++++++++++++++++++++ Dockerfile | 31 ++++++++++++++++ Makefile | 36 ++++++++++++++++++ README.md | 40 ++++++++++++++++++++ doc.go | 1 + go.mod | 8 ++++ go.sum | 7 ++++ main.go | 36 ++++++++++++++++++ main_test.go | 9 +++++ renovate.json | 6 +++ smsify/doc.go | 1 + smsify/smsify.go | 87 ++++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 523 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100644 doc.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 main_test.go create mode 100644 renovate.json create mode 100644 smsify/doc.go create mode 100644 smsify/smsify.go diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..792dfc0 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,53 @@ +version: 2.1 + +executors: + golang: + working_directory: /go/src/ultre.me/smsify + docker: + - image: circleci/golang:1.12 + environment: + GO111MODULE: "on" + DOCKER_IMAGE: ultreme/smsify + + docker: + docker: + - image: docker:18.06.3-ce-git + +orbs: + codecov: codecov/codecov@1.0.5 + ultreme: ultreme/build@1.5.0 + retry: ultreme/retry@0.6.0 + docker: circleci/docker@0.5.13 + #dl: ultreme/dl@1.7.0 + tools: gotest/tools@0.0.10 + +jobs: + go-build: + executor: golang + steps: + - checkout + - retry/install + - tools/mod-download + - tools/mod-tidy-check + - run: retry -m 3 make install + - run: retry -m 3 make test + - ultreme/install_golangci-lint + - run: PATH=$PATH:$(pwd)/bin retry -m 3 make lint + - codecov/upload: + file: coverage.txt + + docker-build: + executor: docker + steps: + - checkout + - setup_remote_docker: + docker_layer_caching: true + - docker/build: + image: ultreme/smsify + #- docker/dockerlint + +workflows: + main: + jobs: + - go-build + - docker-build diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e358cd7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,35 @@ +## +## Specific to .dockerignore +## + +.git/ +Dockerfile +contrib/ + +## +## Common with .gitignore +## + +# Temporary files +*~ +*# +.#* + +# Vendors +node_modules/ +vendor/ + +# Binaries for programs and plugins +dist/ +gin-bin +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..730513c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,63 @@ +root = true + +[*] +charset = utf-8 + +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab + +[*.go] +indent_style = tab + +[*.proto] +indent_size = 2 + +[*.swift] +indent_size = 4 + +[*.tmpl] +indent_size = 2 + +[*.js] +indent_size = 2 +block_comment_start = /* +block_comment_end = */ + +[*.html] +indent_size = 2 + +[*.bat] +end_of_line = crlf + +[*.{json,yml}] +indent_size = 2 + +[.{babelrc,eslintrc}] +indent_size = 2 + +[{Fastfile,.buckconfig,BUCK}] +indent_size = 2 + +[*.diff] +indent_size = 1 + +[*.m] +indent_size = 1 +indent_style = space +block_comment_start = /** +block_comment = * +block_comment_end = */ + +[*.java] +indent_size = 4 +indent_style = space +block_comment_start = /** +block_comment = * +block_comment_end = */ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c96f81b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Collapse vendored and generated files on GitHub +vendor/* linguist-vendored +*/vendor/* linguist-vendored +*.gen.* linguist-generated +*.pb.go linguist-generated + +# Reduce conflicts on markdown files +*.md merge=union diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..60f6c2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Temporary files +*~ +*# +.#* +coverage.txt + +# Vendors +node_modules/ +vendor/ + +# Binaries for programs and plugins +dist/ +gin-bin +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..cf01fa4 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,34 @@ +run: + deadline: 1m + tests: false + #skip-files: + # - ".*\\.gen\\.go" + +linters-settings: + golint: + min-confidence: 0 + maligned: + suggest-new: true + goconst: + min-len: 5 + min-occurrences: 4 + misspell: + locale: US + +linters: + disable-all: true + enable: + - goconst + - misspell + - deadcode + - misspell + - structcheck + - errcheck + - unused + - varcheck + - staticcheck + - unconvert + - gofmt + - goimports + - golint + - ineffassign diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..d79069b --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,41 @@ +before: + hooks: + - go mod download +builds: + - + goos: [linux, darwin, windows] + goarch: [386, amd64, arm, arm64] + flags: + - "-a" + ldflags: + - '-extldflags "-static"' + env: + - CGO_ENABLED=0 +archives: + - wrap_in_directory: true + replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +brew: + name: smsify + github: + owner: ultreme + name: homebrew-ultreme + commit_author: + name: ultreme-bot + email: "bot@ultre.me" + homepage: https://ultre.me/ + description: "smsify" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..de3422f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# dynamic config +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION + +# build +FROM golang:1.12-alpine as builder +RUN apk add --no-cache git gcc musl-dev make +ENV GO111MODULE=on +WORKDIR /go/src/ultre.me/smsify +COPY go.* ./ +RUN go mod download +COPY . ./ +RUN make install + +# minimalist runtime +FROM alpine:3.10 +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="smsify" \ + org.label-schema.description="" \ + org.label-schema.url="https://ultre.me/smsify/" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://github.com/ultreme/smsify" \ + org.label-schema.vendor="Manfred Touron" \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" \ + org.label-schema.cmd="docker run -i -t --rm ultreme/smsify" \ + org.label-schema.help="docker exec -it $CONTAINER smsify --help" +COPY --from=builder /go/bin/smsify /bin/ +ENTRYPOINT ["/bin/smsify"] +#CMD [] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..12d6745 --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +GO ?= go +DOCKER_IMAGE ?= ultreme/smsify + +.PHONY: install +install: + $(GO) install . + +.PHONY: test +test: + echo "" > /tmp/coverage.txt + set -e; for dir in `find . -type f -name "go.mod" | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \ + cd $$dir; \ + $(GO) test -mod=readonly -v -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \ + if [ -f /tmp/profile.out ]; then \ + cat /tmp/profile.out >> /tmp/coverage.txt; \ + rm -f /tmp/profile.out; \ + fi); done + mv /tmp/coverage.txt . + +.PHONY: lint +lint: + golangci-lint run --verbose ./... + +.PHONY: release +release: + goreleaser --snapshot --skip-publish --rm-dist + @echo -n "Do you want to release? [y/N] " && read ans && [ $${ans:-N} = y ] + goreleaser --rm-dist + +.PHONY: docker +docker: + docker build \ + --build-arg VCS_REF=`git rev-parse --short HEAD` \ + --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ + --build-arg VERSION=`git describe --tags --always` \ + -t $(DOCKER_IMAGE) . diff --git a/README.md b/README.md new file mode 100644 index 0000000..94f87c0 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# smsify + +:smile: smsify + +[![CircleCI](https://circleci.com/gh/ultreme/smsify.svg?style=shield)](https://circleci.com/gh/ultreme/smsify) +[![GoDoc](https://godoc.org/ultre.me/smsify?status.svg)](https://godoc.org/ultre.me/smsify) +[![License](https://img.shields.io/github/license/ultreme/smsify.svg)](https://github.com/ultreme/smsify/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/ultreme/smsify.svg)](https://github.com/ultreme/smsify/releases) +[![Go Report Card](https://goreportcard.com/badge/ultre.me/smsify)](https://goreportcard.com/report/ultre.me/smsify) +[![CodeFactor](https://www.codefactor.io/repository/github/ultreme/smsify/badge)](https://www.codefactor.io/repository/github/ultreme/smsify) +[![codecov](https://codecov.io/gh/ultreme/smsify/branch/master/graph/badge.svg)](https://codecov.io/gh/ultreme/smsify) +[![Docker Metrics](https://images.microbadger.com/badges/image/ultreme/smsify.svg)](https://microbadger.com/images/ultreme/smsify) +[![Sourcegraph](https://sourcegraph.com/github.com/ultreme/smsify/-/badge.svg)](https://sourcegraph.com/github.com/ultreme/smsify?badge) +[![Made by Ultreme M1ch3l](https://img.shields.io/badge/made%20by-Ultreme%20M1ch3l-blue.svg?style=flat)](https://ultre.me/) + + +## Usage + +```console +$ smsify -h +... +``` + +## Install + +### Using go + +```console +$ go get -u ultre.me/smsify +``` + +### Using brew + +```console +$ brew install ultreme/ultreme/smsify +``` + +### Download releases + +https://github.com/ultreme/smsify/releases diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..2023506 --- /dev/null +++ b/doc.go @@ -0,0 +1 @@ +package main // import "ultre.me/smsify" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..04144ad --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module ultre.me/smsify + +go 1.12 + +require ( + github.com/urfave/cli v1.21.0 + gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5114dcf --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE= +github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +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= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go new file mode 100644 index 0000000..62677dd --- /dev/null +++ b/main.go @@ -0,0 +1,36 @@ +package main // import "ultre.me/smsify" + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "strings" + + cli "gopkg.in/urfave/cli.v2" + "ultre.me/smsify/smsify" +) + +func main() { + 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 := smsify.Smsify(message) + fmt.Println(out) + return nil +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..a43d927 --- /dev/null +++ b/main_test.go @@ -0,0 +1,9 @@ +package main + +import "os" + +func Example() { + os.Args = []string{"", "Salut ça va ?"} + main() + // Output: slt sa va? +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..031be2c --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "extends": [ + "config:base" + ], + "groupName": "all" +} diff --git a/smsify/doc.go b/smsify/doc.go new file mode 100644 index 0000000..8cdef8b --- /dev/null +++ b/smsify/doc.go @@ -0,0 +1 @@ +package smsify // import "ultre.me/smsify/smsify" diff --git a/smsify/smsify.go b/smsify/smsify.go new file mode 100644 index 0000000..df1aff6 --- /dev/null +++ b/smsify/smsify.go @@ -0,0 +1,87 @@ +package smsify + +import "strings" + +var mapping = [][2]string{ // FIXME: use a .csv file and go generate + {"salut", "slt"}, + {"ça", "sa"}, + {"coucou", "cc"}, + {"comment", "cmt"}, + {" ?", "?"}, + {"fallait", "falé"}, + {"que", "ke"}, // FIXME: we should only replace the complete word "que", not everytime we meet "que" somewhere in a text + {"je te", "j'te"}, + {"petite", "ptite"}, + {"petit", "pti"}, + {"que", "ke"}, + {"je t'aime", "jtaime"}, + {"quoi", "koi"}, + {"venir", "vnir"}, + {"quand", "kan"}, + {"unique", "unik"}, + {"d'aussi", "doci"}, + {"aussi", "oci"}, + {"tout", "tt"}, + {"devant", "dvan"}, + {"t'as", "ta"}, + {"j'ai", "jé"}, + {"dehors", "dehor"}, + {"je vais", "jv"}, + {"pour", "pr"}, + {"parceque", "pck"}, + {"je viens", "jv1"}, + {"d'autre", "dotr"}, + {"autre", "otr"}, + {"t'inquiete", "tkt"}, + {"peut-être", "ptet"}, + {"moins", "moin"}, + {"vrai", "vré"}, + {"jamais", "jamé"}, + {"connais", "coné"}, + {"connait", "coné"}, + {"bisous", "bisou"}, + {"mon", "mn"}, + {"l'heure", "lheur"}, + {"gros", "gro"}, + {"qui", "ki"}, + {"c'était", "cété"}, + {"claire", "klr"}, + {"c'est", "c"}, + {"plus", "plu"}, + {"t'es", "t"}, + {"je voulais", "jvoulé"}, + {"voulais", "voulé"}, + {"voulait", "voulé"}, + {"comme", "kom"}, + {"commentaire", "kom"}, + {"quitter", "kité"}, + {"qu'on", "kn"}, + {"quelqu'un", "qqn"}, + {"j'ai", "g"}, + {"qu'a", "ka"}, + {"demain", "dem1"}, + {"manque", "mank"}, + {"aller", "allé"}, + {"cinéma", "ciné"}, + {"nouvelle", "nouvel"}, + {"seulement", "seulmen"}, + {"vrai", "vré"}, + {"seulement", "seulmen"}, + {"prendre", "prendr"}, + {"comme", "km"}, + {"moment", "momen"}, + {"ça fait", "sfé"}, + {"surtout", "surtt"}, + {"gueule", "gueul"}, + {"partout", "partt"}, +} + +func Smsify(input string) string { + input = strings.ToLower(input) + for _, pair := range mapping { + input = strings.Replace(input, pair[0], pair[1], -1) + } + return input +} + +// FIXME: implement "Unsmsify" :)