2020-11-25 11:01:53 +00:00
|
|
|
package all
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-12-04 01:36:16 +00:00
|
|
|
"github.com/xtls/xray-core/common/uuid"
|
|
|
|
"github.com/xtls/xray-core/main/commands/base"
|
2020-11-25 11:01:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var cmdUUID = &base.Command{
|
2021-01-12 18:23:54 +00:00
|
|
|
UsageLine: `{{.Exec}} uuid [-i "example"]`,
|
|
|
|
Short: `Generate UUIDv4 or UUIDv5`,
|
2020-11-25 11:01:53 +00:00
|
|
|
Long: `
|
2021-01-12 18:23:54 +00:00
|
|
|
Generate UUIDv4 or UUIDv5.
|
|
|
|
|
|
|
|
UUIDv4 (random): {{.Exec}} uuid
|
|
|
|
|
|
|
|
UUIDv5 (from input): {{.Exec}} uuid -i "example"
|
|
|
|
`,
|
2020-11-25 11:01:53 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 18:23:54 +00:00
|
|
|
func init() {
|
|
|
|
cmdUUID.Run = executeUUID // break init loop
|
|
|
|
}
|
|
|
|
|
|
|
|
var input = cmdUUID.Flag.String("i", "", "")
|
|
|
|
|
2020-11-25 11:01:53 +00:00
|
|
|
func executeUUID(cmd *base.Command, args []string) {
|
2021-01-12 18:23:54 +00:00
|
|
|
var output string
|
|
|
|
if l := len(*input); l == 0 {
|
|
|
|
u := uuid.New()
|
|
|
|
output = u.String()
|
|
|
|
} else if l <= 30 {
|
|
|
|
u, _ := uuid.ParseString(*input)
|
|
|
|
output = u.String()
|
|
|
|
} else {
|
|
|
|
output = "Input must be within 30 bytes."
|
|
|
|
}
|
|
|
|
fmt.Println(output)
|
2020-11-25 11:01:53 +00:00
|
|
|
}
|