Select Git revision
templateCreate.go
templateCreate.go 1.05 KiB
package cmdTemplate
import (
u "nexus-client/utils"
g "nexus-client/globals"
)
type Create struct {
Name string
}
func (cmd *Create)GetName() string {
return cmd.Name
}
func (cmd *Create)GetDesc() string {
return "Create a template."
}
func (cmd *Create)PrintUsage() {
u.PrintlnErr(cmd.GetDesc())
u.PrintlnErr("Usage: "+cmd.Name+" vmID name access")
u.PrintlnErr("Notes: access is either \"public\" or \"private\"")
}
func (cmd *Create)Run(args []string) int {
client := g.GetInstance().Client
host := g.GetInstance().Host
argc := len(args)
if argc != 3 {
cmd.PrintUsage()
return 1
}
vmID := args[0]
name := args[1]
access := args[2]
type TemplateArgs struct {
VMID string
Name string
Access string
}
templateArgs := &TemplateArgs { vmID, name, access }
resp, err := client.R().SetBody(templateArgs).Post(host+"/templates")
if err != nil {
u.PrintlnErr("Error: "+err.Error())
return 1
}
if resp.IsSuccess() {
u.Println(resp)
return 0
} else {
u.PrintlnErr("Error: "+resp.Status()+": "+resp.String())
return 1
}
}