1 回答

TA貢獻(xiàn)1784條經(jīng)驗 獲得超2個贊
在 .之后傳遞你的標(biāo)志--。雙破折號 (--) 用于表示命令選項的結(jié)尾。在我們的例子中,需要區(qū)分傳遞給的標(biāo)志go和沒有傳遞的標(biāo)志。雙破折號后的所有內(nèi)容都不會被視為go的標(biāo)志。
我嘗試使用 gcloud:
package cmd
import (
"fmt"
"os/exec"
"github.com/spf13/cobra"
)
var gcloudCmd = &cobra.Command{
Use: "gcloud",
Short: "run gcloud",
Run: func(cmd *cobra.Command, args []string) {
out, err := exec.Command("gcloud", args...).Output()
if err != nil {
fmt.Println(err)
}
fmt.Println(string(out))
},
}
func init() {
rootCmd.AddCommand(gcloudCmd)
}
然后嘗試:
$ go run . gcloud compute regions list -- --filter="id<1250"
NAME CPUS DISKS_GB ADDRESSES RESERVED_ADDRESSES STATUS TURNDOWN_DATE
asia-east1 0/24 0/4096 0/8 0/8 UP
europe-west1 0/24 0/4096 0/8 0/8 UP
us-central1 0/24 0/4096 0/8 0/8 UP
us-east1 0/24 0/4096 0/8 0/8 UP
us-west1 0/24 0/4096 0/8 0/8 UP
添加更多標(biāo)志:
$ go run . gcloud compute regions list -- --filter="id<1250" --format="table(name,id)"
NAME ID
asia-east1 1220
europe-west1 1100
us-central1 1000
us-east1 1230
us-west1 1210
- 1 回答
- 0 關(guān)注
- 88 瀏覽
添加回答
舉報