go 语言学习〇

package main

import (
	"fmt"
	"os"
)

func main() {

	if len(os.Args) < 2 {
		fmt.Printf("usage:%s help", os.Args[0])
		os.Exit(0)
	}

	switch os.Args[1] {
	case "help":
		fmt.Printf("%s help : print the help message.
", os.Args[0])
		fmt.Printf("%s version : print the app version.", os.Args[0])

	case "version":
		fmt.Printf("version 1.0
")
		//不同于c 和 java, go 的 switch case 语句无须显式增加 break 执行上也不会贯穿
		//不过如果你看的不顺眼非要加上 break 也不会错
		//相反, 如果想要贯穿还需要明确的增加 fallthrough 关键字
		fallthrough
	default:
		fmt.Printf("run %s help for usage.", os.Args[0])

	}
}
原文地址:https://www.cnblogs.com/scala/p/9151658.html