1
0
Fork 0
mirror of https://github.com/Luzifer/slugify.git synced 2024-11-10 09:10:01 +00:00
slugify/main.go

48 lines
831 B
Go
Raw Permalink Normal View History

2017-12-15 10:31:48 +00:00
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/Luzifer/rconfig/v2"
2017-12-15 10:31:48 +00:00
"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)
}