()
| 13 | ) |
| 14 | |
| 15 | func main() { |
| 16 | plugin.Run(func(dockerCLI command.Cli) *cobra.Command { |
| 17 | goodbye := &cobra.Command{ |
| 18 | Use: "goodbye", |
| 19 | Short: "Say Goodbye instead of Hello", |
| 20 | Run: func(cmd *cobra.Command, _ []string) { |
| 21 | _, _ = fmt.Fprintln(dockerCLI.Out(), "Goodbye World!") |
| 22 | }, |
| 23 | } |
| 24 | apiversion := &cobra.Command{ |
| 25 | Use: "apiversion", |
| 26 | Short: "Print the API version of the server", |
| 27 | RunE: func(_ *cobra.Command, _ []string) error { |
| 28 | apiClient := dockerCLI.Client() |
| 29 | ping, err := apiClient.Ping(context.Background(), client.PingOptions{}) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | _, _ = fmt.Println(ping.APIVersion) |
| 34 | return nil |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | exitStatus2 := &cobra.Command{ |
| 39 | Use: "exitstatus2", |
| 40 | Short: "Exit with status 2", |
| 41 | RunE: func(_ *cobra.Command, _ []string) error { |
| 42 | _, _ = fmt.Fprintln(dockerCLI.Err(), "Exiting with error status 2") |
| 43 | os.Exit(2) |
| 44 | return nil |
| 45 | }, |
| 46 | } |
| 47 | |
| 48 | var ( |
| 49 | who, optContext string |
| 50 | preRun, debug bool |
| 51 | ) |
| 52 | cmd := &cobra.Command{ |
| 53 | Use: "helloworld", |
| 54 | Short: "A basic Hello World plugin for tests", |
| 55 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 56 | if err := plugin.PersistentPreRunE(cmd, args); err != nil { |
| 57 | return err |
| 58 | } |
| 59 | if preRun { |
| 60 | _, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin PersistentPreRunE called") |
| 61 | } |
| 62 | return nil |
| 63 | }, |
| 64 | RunE: func(cmd *cobra.Command, args []string) error { |
| 65 | if debug { |
| 66 | _, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin debug mode enabled") |
| 67 | } |
| 68 | |
| 69 | switch optContext { |
| 70 | case "Christmas": |
| 71 | _, _ = fmt.Fprintln(dockerCLI.Out(), "Merry Christmas!") |
| 72 | return nil |
nothing calls this directly
no test coverage detected
searching dependent graphs…