Parse command-line arguments

package main

import (
    "fmt"
    "flag"
    "math/rand"
)

func main() { 
    // Define flags 
    max := flag.Int("max", 6, "the max value") 
    // Parse 
    flag.Parse() 
    // Generate a number between 0 and max 
    fmt.Println(rand.Intn(*max)) 
}

你可能感兴趣的:(Parse command-line arguments)