2017-12-15 10:31:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2021-10-13 16:03:25 +00:00
|
|
|
"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)
|
|
|
|
}
|