NewAliasSetCommand creates and returns the cobra command for setting an alias.
()
| 9 | |
| 10 | // NewAliasSetCommand creates and returns the cobra command for setting an alias. |
| 11 | func NewAliasSetCommand() *cobra.Command { |
| 12 | cmd := &cobra.Command{ |
| 13 | Use: "set <alias> [flags]", |
| 14 | Args: cobra.ExactArgs(1), |
| 15 | Short: "Set an alias for the specified server address", |
| 16 | Long: "Set an alias for the specified server address", |
| 17 | Run: func(cmd *cobra.Command, args []string) { |
| 18 | aliasContent := args[0] |
| 19 | targetAddress, _ := cmd.Flags().GetString("target") |
| 20 | configuration, err := config.LoadConfig() |
| 21 | if err != nil { |
| 22 | utils.Fatalln(err) |
| 23 | } |
| 24 | controller := control.NewAliasController(targetAddress, configuration, aliasContent) |
| 25 | controller.SetAlias() |
| 26 | }, |
| 27 | } |
| 28 | cmd.Flags().StringP( |
| 29 | "target", "t", "", "Set the alias for the target server address") |
| 30 | _ = cmd.MarkFlagRequired("target") |
| 31 | return cmd |
| 32 | } |