Skip to content

Commit

Permalink
Add command to generate empty/nil UUID (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
slomek authored Oct 3, 2020
1 parent 245174b commit 22d9644
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// empty represents command generating empty UUID.
var empty = &cobra.Command{
Use: "empty",
Aliases: []string{"nil"},
Short: "Generate empty uuid",
Long: `Generate empty:
Generates empty (all-zeroes) uuid
`,
Run: func(cmd *cobra.Command, args []string) {
const emptyUUID = "00000000-0000-0000-0000-000000000000"

fmt.Println(emptyUUID)
},
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Execute() {
func init() {

rootCmd.AddCommand(v4Cmd)
rootCmd.AddCommand(empty)

cobra.OnInitialize(initConfig)

Expand Down
11 changes: 11 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "os"

func ExampleGenerateEmpty() {
// Pass argument to test 'uuid empty' command.
os.Args = append(os.Args, "empty")

main()
// Output: 00000000-0000-0000-0000-000000000000
}

0 comments on commit 22d9644

Please sign in to comment.