Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var IdCommand = &cli.Command{ Name: "id", Description: "Prints a random ID", Flags: []cli.Flag{ common.CountFlag, &cli.StringFlag{ Name: "type", Aliases: []string{"t"}, Usage: fmt.Sprintf("Type of the id, must be one of [%s]", strings.Join(common.ID_TYPES, ", ")), Value: common.ID_TYPE_UUID4, Action: func(ctx *cli.Context, s string) error { if !slices.Contains(common.ID_TYPES, s) { return fmt.Errorf("invalid id type %q", s) } return nil }, }, }, Action: func(ctx *cli.Context) error { count := ctx.Int("count") idType := ctx.String("type") ids := make([]string, 0, count) for range count { var id string var err error if idType == common.ID_TYPE_UUID4 { id = uuid.New().String() } if idType == common.ID_TYPE_UUID7 { var _id uuid.UUID _id, err = uuid.NewV7() id = _id.String() } if idType == common.ID_TYPE_NANO { id, err = gonanoid.New() } if err != nil { return fmt.Errorf("error generating nanoid: %w", err) } ids = append(ids, id) } common.Std.Println(strings.Join(ids, "\n")) return nil }, }
View Source
var PickCommand = &cli.Command{ Name: "pick", Description: "Picks and print a random item from the given items", Flags: []cli.Flag{ common.CountFlag, &cli.StringFlag{ Name: "delimiter", Aliases: []string{"d"}, Usage: "Delimiter for the shuffled output", Value: common.DEFAULT_DELIMITER, }, &cli.IntFlag{ Name: "number", Aliases: []string{"n"}, Usage: "Number of items to pick", Value: 1, }, }, Action: func(ctx *cli.Context) error { count := ctx.Int("count") delimiter := ctx.String("delimiter") number := ctx.Int("number") values := ctx.Args().Slice() if len(values) == 0 { return nil } randomChoices := make([]string, 0, count) for range count { shuffledItems := helpers.Shuffle(values) chosenItems := shuffledItems[:number] randomChoices = append(randomChoices, strings.Join(chosenItems, delimiter)) } common.Std.Println(strings.Join(randomChoices, "\n")) return nil }, }
View Source
var ShuffleCommand = &cli.Command{ Name: "shuffle", Description: "Shuffles the given items", Flags: []cli.Flag{ common.CountFlag, &cli.StringFlag{ Name: "delimiter", Aliases: []string{"d"}, Usage: "Delimiter for the shuffled output", Value: common.DEFAULT_DELIMITER, }, }, Action: func(ctx *cli.Context) error { count := ctx.Int("count") delimiter := ctx.String("delimiter") values := ctx.Args().Slice() if len(values) == 0 { return nil } randomShuffles := make([]string, 0, count) for range count { shuffledItems := helpers.Shuffle(values) randomShuffles = append(randomShuffles, strings.Join(shuffledItems, delimiter)) } common.Std.Println(strings.Join(randomShuffles, "\n")) return nil }, }
View Source
var StringCommand = &cli.Command{ Name: "string", Aliases: []string{"str"}, Description: "Prints a random string", Flags: []cli.Flag{ common.CountFlag, &cli.IntFlag{ Name: "length", Aliases: []string{"l"}, Usage: "Length of the random string", Value: common.DEFAULT_STRING_LENGTH, }, &cli.StringFlag{ Name: "type", Aliases: []string{"t"}, Usage: fmt.Sprintf("Type of the random string, must be one of [%s]", strings.Join(common.STRING_TYPES, ", ")), Value: common.STRING_TYPE_ASCII, Action: func(ctx *cli.Context, s string) error { if !slices.Contains(common.STRING_TYPES, s) { return fmt.Errorf("invalid string type %q", s) } return nil }, }, }, Action: func(ctx *cli.Context) error { count := ctx.Int("count") length := ctx.Int("length") strType := ctx.String("type") randomStrings := make([]string, 0, count) for range count { randomStrings = append(randomStrings, helpers.GetRandomString(strType, length)) } common.Std.Println(strings.Join(randomStrings, "\n")) return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.