Пример #1
0
var templateDetailsID string

var templateDetailsCmd = &cobra.Command{
	Use:     "details",
	Aliases: []string{"show", "info"},
	Short:   "Show full details about a template",
	Example: "civo templates details --name ubuntu-70.04",
	Long:    `Show the full details for a template`,
	Run: func(cmd *cobra.Command, args []string) {
		if templateDetailsID == "" {
			fmt.Println("You need to specify an ID with --id in order to show a template's full details")
			os.Exit(-3)
		}

		res, err := api.TemplateFind(templateDetailsID)
		if err != nil {
			errorColor := color.New(color.FgRed, color.Bold).SprintFunc()
			fmt.Println(errorColor("An error occured:"), err.Error())
			return
		}
		// fmt.Println(res.String())
		fmt.Printf("%-20s: %s\n", "ID", res.Path("id").Data().(string))
		fmt.Printf("%-20s: %s\n", "Name", res.Path("name").Data().(string))
		fmt.Printf("%-20s: %s\n", "Image ID", res.Path("image_id").Data().(string))
		fmt.Printf("%-20s: %s\n", "Short Description", res.Path("short_description").Data().(string))
		fmt.Printf("%-20s: %s\n", "Description", res.Path("description").Data().(string))
		fmt.Println("")
		fmt.Println(">>>>> Cloud Config <<<<<")
		fmt.Println(res.Path("cloud_config").Data().(string))
	},
Пример #2
0
var templateUpdateCloudInitFile string

var templateUpdateCmd = &cobra.Command{
	Use:     "update",
	Aliases: []string{"save"},
	Short:   "Save a template",
	Example: "civo templates update --id ubuntu-70.04 --image-id b834b08c-bec6-11e5-b756-5cf9389be614",
	Long:    `Update a template with new parameters for people to use to build images from`,
	Run: func(cmd *cobra.Command, args []string) {
		if templateUpdateID == "" {
			fmt.Println("You need to specify a name with --id in order to update a template")
			os.Exit(-3)
		}

		params := api.TemplateParams{}
		res, err := api.TemplateFind(templateUpdateID)
		if err != nil {
			errorColor := color.New(color.FgRed, color.Bold).SprintFunc()
			fmt.Println(errorColor("An error occured:"), err.Error())
			return
		}
		params.ID = res.Path("id").Data().(string)
		params.Name = res.Path("name").Data().(string)
		params.ImageID = res.Path("image_id").Data().(string)
		params.ShortDescription = res.Path("short_description").Data().(string)
		params.Description = res.Path("description").Data().(string)
		params.CloudConfig = res.Path("cloud_config").Data().(string)

		if templateUpdateName != "" {
			params.Name = templateUpdateName
		}