NewCachesCommand creates and returns the cobra command for creating a cache entry.
()
| 10 | |
| 11 | // NewCachesCommand creates and returns the cobra command for creating a cache entry. |
| 12 | func NewCachesCommand() *cobra.Command { |
| 13 | cmd := &cobra.Command{ |
| 14 | Use: "caches <cache>", |
| 15 | Short: "Create an alternative cache", |
| 16 | Long: "Create an alternative cache", |
| 17 | Aliases: []string{"cache"}, |
| 18 | Run: func(cmd *cobra.Command, _ []string) { |
| 19 | newIP, _ := cmd.Flags().GetString("ip") |
| 20 | newUser, _ := cmd.Flags().GetString("user") |
| 21 | newPort, _ := cmd.Flags().GetString("port") |
| 22 | newPassword, _ := cmd.Flags().GetString("pwd") |
| 23 | newAlias, _ := cmd.Flags().GetString("alias") |
| 24 | newCacheContent := control.CacheContent{ |
| 25 | IP: newIP, |
| 26 | User: newUser, |
| 27 | Port: newPort, |
| 28 | Password: newPassword, |
| 29 | Alias: newAlias, |
| 30 | } |
| 31 | contentJSON, err := json.Marshal(newCacheContent) //nolint:gosec // G117: password is needed for cache storage |
| 32 | if err != nil { |
| 33 | utils.Errorln("Cache content JSON marshal failed.") |
| 34 | return |
| 35 | } |
| 36 | configuration, loadErr := config.LoadConfig() |
| 37 | if loadErr != nil { |
| 38 | utils.Fatalln(loadErr) |
| 39 | } |
| 40 | controller := control.NewCreateController(control.TypeCaches, string(contentJSON), configuration) |
| 41 | controller.ExecuteCreate() |
| 42 | }, |
| 43 | } |
| 44 | cmd.Flags().StringP("ip", "i", "", "The ipaddress of the cache to be added") |
| 45 | cmd.Flags().StringP("user", "u", "", "The username of the cache to be added") |
| 46 | cmd.Flags().StringP("port", "P", "", "The port of the cache to be added") |
| 47 | cmd.Flags().StringP("pwd", "p", "", "The password of the cache to be added") |
| 48 | cmd.Flags().StringP("alias", "a", "", "The alias of the cache to be added") |
| 49 | |
| 50 | _ = cmd.MarkFlagRequired("ip") |
| 51 | _ = cmd.MarkFlagRequired("user") |
| 52 | _ = cmd.MarkFlagRequired("port") |
| 53 | _ = cmd.MarkFlagRequired("pwd") |
| 54 | return cmd |
| 55 | } |