1
0
Fork 0
mirror of https://github.com/Luzifer/slugify.git synced 2024-11-14 02:52:42 +00:00
slugify/main.go
Knut Ahlers 0178deed47
Add go modules support, update dependencies
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-10-13 18:03:25 +02:00

47 lines
831 B
Go

package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/Luzifer/rconfig/v2"
"github.com/gosimple/slug"
)
var (
cfg = struct {
MaxLength int `flag:"max-length,l" default:"0" description:"Maximum length of returned slug (0 = no limit)"`
VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"`
}{}
version = "dev"
)
func init() {
if err := rconfig.Parse(&cfg); err != nil {
log.Fatalf("Unable to parse commandline options: %s", err)
}
if cfg.VersionAndExit {
fmt.Printf("git-changerelease %s\n", version)
os.Exit(0)
}
}
func main() {
parts := rconfig.Args()[1:]
var s string
for {
s = slug.Make(strings.Join(parts, " "))
if cfg.MaxLength == 0 || len(s) < cfg.MaxLength {
break
}
parts = parts[0 : len(parts)-1]
}
fmt.Println(s)
}