-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac.go
46 lines (36 loc) · 777 Bytes
/
mac.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
func newMacAddressCommand() *cobra.Command {
cmd := &cobra.Command{
Short: "Generate a valid, random, locally administered, unicast MAC address",
Use: "macaddress",
RunE: func(cmd *cobra.Command, args []string) error {
globalOptions, err := newGlobalOptions(cmd)
if err != nil {
return err
}
if err := runMacAddress(globalOptions); err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
return nil
},
}
return cmd
}
func runMacAddress(opts *globalOptions) error {
eng, err := newEngine(opts)
if err != nil {
return err
}
macAddress, err := eng.RandomLocallyAdministeredMacAddress()
if err != nil {
return err
}
fmt.Println(macAddress)
return nil
}