<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] 參考連接:[https://studygolang.com/articles/7588](https://studygolang.com/articles/7588) [github](https://github.com/spf13/cobra) ## Cobra提供的功能 * 簡易的子命令行模式,如 app server, app fetch等等 * 完全兼容posix命令行模式 * 嵌套子命令subcommand * 支持全局,局部,串聯flags * 使用Cobra很容易的生成應用程序和命令,使用cobra create appname和cobra add cmdname * 如果命令輸入錯誤,將提供智能建議,如 app srver,將提示srver沒有,是否是app server * 自動生成commands和flags的幫助信息 * 自動生成詳細的help信息,如app help * 自動識別-h,--help幫助flag * 自動生成應用程序在bash下命令自動完成功能 * 自動生成應用程序的man手冊 * 命令行別名 * 自定義help和usage信息 * 可選的緊密集成的[viper](http://github.com/spf13/viper)apps ## 示例 ``` package main import ( "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" "os" ) //------自定義error------- type pubError struct { s string } func (pe *pubError) Error() string { return pe.s } //----------------------- var rootCmd = &cobra.Command{ Use: "demo", Short: "demo is a test cobra", Long: `A Fast and Flexible Static Site Generator built with love by spf13 and friends in Go. Complete documentation is available at http://hugo.spf13.com`, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("demo Static Site Generator v0.9 -- HEAD") return &pubError{"123"} }, } func init() { rootCmd.PersistentFlags().StringP("config", "c", "config.json", "Configuration file to use.") rootCmd.PersistentFlags().Bool("platform", false, "This flag signifies that the user tried to start the command from the platform binary, so we can log a mssage") rootCmd.PersistentFlags().MarkHidden("platform") viper.SetEnvPrefix("demo") viper.BindEnv("config") viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config")) } func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } } func main() { Execute() } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看