• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang doit.NewMissingArgsErr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bryanl/doit.NewMissingArgsErr函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMissingArgsErr函数的具体用法?Golang NewMissingArgsErr怎么用?Golang NewMissingArgsErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewMissingArgsErr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: RunKeyUpdate

// RunKeyUpdate updates a key.
func RunKeyUpdate(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	rawKey := args[0]

	name, err := config.GetString(ns, doit.ArgKeyName)
	if err != nil {
		return err
	}

	req := &godo.KeyUpdateRequest{
		Name: name,
	}

	var key *godo.Key
	if i, aerr := strconv.Atoi(rawKey); aerr == nil {
		key, _, err = client.Keys.UpdateByID(i, req)
	} else {
		key, _, err = client.Keys.UpdateByFingerprint(rawKey, req)
	}

	if err != nil {
		return err
	}

	return doit.DisplayOutput(key, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:32,代码来源:sshkeys.go


示例2: RunKeyGet

// RunKeyGet retrieves a key.
func RunKeyGet(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	rawKey := args[0]

	var err error
	var key *godo.Key

	if i, aerr := strconv.Atoi(rawKey); aerr == nil {
		key, _, err = client.Keys.GetByID(i)
	} else {
		if len(rawKey) > 0 {
			key, _, err = client.Keys.GetByFingerprint(rawKey)
		} else {
			err = fmt.Errorf("missing key id or fingerprint")
		}
	}

	if err != nil {
		return err
	}

	return doit.DisplayOutput(key, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:29,代码来源:sshkeys.go


示例3: RunDropletActionResize

// RunDropletActionResize resizesx a droplet giving a size slug and
// optionally expands the disk.
func RunDropletActionResize(ns string, config doit.Config, out io.Writer, args []string) error {
	fn := func(client *godo.Client) (*godo.Action, error) {
		if len(args) != 1 {
			return nil, doit.NewMissingArgsErr(ns)
		}
		id, err := strconv.Atoi(args[0])

		if err != nil {
			return nil, err
		}

		size, err := config.GetString(ns, doit.ArgImageSlug)
		if err != nil {
			return nil, err
		}

		disk, err := config.GetBool(ns, doit.ArgResizeDisk)
		if err != nil {
			return nil, err
		}

		a, _, err := client.DropletActions.Resize(id, size, disk)
		return a, err
	}

	return performAction(out, config, fn)
}
开发者ID:alexcb,项目名称:doit,代码行数:29,代码来源:droplet_actions.go


示例4: RunImagesGet

// RunImagesGet retrieves an image by id or slug.
func RunImagesGet(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	rawID := args[0]

	var image *godo.Image
	var err error

	if id, cerr := strconv.Atoi(rawID); cerr == nil {
		image, _, err = client.Images.GetByID(id)
	} else {
		if len(rawID) > 0 {
			image, _, err = client.Images.GetBySlug(rawID)
		} else {
			err = fmt.Errorf("image identifier is required")
		}
	}

	if err != nil {
		return err
	}

	return doit.DisplayOutput(image, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:29,代码来源:images.go


示例5: RunKeyCreate

// RunKeyCreate uploads a SSH key.
func RunKeyCreate(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	name := args[0]

	publicKey, err := config.GetString(ns, doit.ArgKeyPublicKey)
	if err != nil {
		return err
	}

	kcr := &godo.KeyCreateRequest{
		Name:      name,
		PublicKey: publicKey,
	}

	r, _, err := client.Keys.Create(kcr)
	if err != nil {
		logrus.WithField("err", err).Fatal("could not create key")
	}

	return doit.DisplayOutput(r, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:27,代码来源:sshkeys.go


示例6: RunDropletActionRebuild

// RunDropletActionRebuild rebuilds a droplet using an image id or slug.
func RunDropletActionRebuild(ns string, config doit.Config, out io.Writer, args []string) error {
	fn := func(client *godo.Client) (*godo.Action, error) {
		if len(args) != 1 {
			return nil, doit.NewMissingArgsErr(ns)
		}
		id, err := strconv.Atoi(args[0])

		if err != nil {
			return nil, err
		}

		image, err := config.GetString(ns, doit.ArgImage)
		if err != nil {
			return nil, err
		}

		var a *godo.Action
		if i, aerr := strconv.Atoi(image); aerr == nil {
			a, _, err = client.DropletActions.RebuildByImageID(id, i)
		} else {
			a, _, err = client.DropletActions.RebuildByImageSlug(id, image)
		}
		return a, err
	}

	return performAction(out, config, fn)
}
开发者ID:alexcb,项目名称:doit,代码行数:28,代码来源:droplet_actions.go


示例7: RunImageActionsTransfer

// RunImageActionsTransfer an image.
func RunImageActionsTransfer(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	id, err := strconv.Atoi(args[0])
	if err != nil {
		return err
	}

	region, err := config.GetString(ns, doit.ArgRegionSlug)
	if err != nil {
		return err
	}

	req := &godo.ActionRequest{
		"region": region,
	}

	action, _, err := client.ImageActions.Transfer(id, req)
	if err != nil {
		logrus.WithField("err", err).Fatal("could not transfer image")
	}

	return doit.DisplayOutput(action, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:29,代码来源:image_actions.go


示例8: RunDomainCreate

// RunDomainCreate runs domain create.
func RunDomainCreate(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}
	domainName := args[0]

	client := config.GetGodoClient()

	ipAddress, err := config.GetString(ns, "ip-address")
	if err != nil {
		return err
	}

	req := &godo.DomainCreateRequest{
		Name:      domainName,
		IPAddress: ipAddress,
	}

	d, _, err := client.Domains.Create(req)
	if err != nil {
		return err
	}

	return doit.DisplayOutput(d, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:26,代码来源:domains.go


示例9: RunImagesUpdate

// RunImagesUpdate updates an image.
func RunImagesUpdate(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	id, err := strconv.Atoi(args[0])
	if err != nil {
		return err
	}

	name, err := config.GetString(ns, doit.ArgImageName)

	req := &godo.ImageUpdateRequest{
		Name: name,
	}

	image, _, err := client.Images.Update(id, req)
	if err != nil {
		return err
	}

	return doit.DisplayOutput(image, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:26,代码来源:images.go


示例10: RunRecordUpdate

// RunRecordUpdate updates a domain record.
func RunRecordUpdate(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}
	domainName := args[0]

	client := config.GetGodoClient()

	recordID, err := config.GetInt(ns, doit.ArgRecordID)
	if err != nil {
		return err
	}

	rType, err := config.GetString(ns, doit.ArgRecordType)
	if err != nil {
		return err
	}

	rName, err := config.GetString(ns, doit.ArgRecordName)
	if err != nil {
		return err
	}

	rData, err := config.GetString(ns, doit.ArgRecordData)
	if err != nil {
		return err
	}

	rPriority, err := config.GetInt(ns, doit.ArgRecordPriority)
	if err != nil {
		return err
	}

	rPort, err := config.GetInt(ns, doit.ArgRecordPort)
	if err != nil {
		return err
	}

	rWeight, err := config.GetInt(ns, doit.ArgRecordWeight)
	if err != nil {
		return err
	}

	drcr := &godo.DomainRecordEditRequest{
		Type:     rType,
		Name:     rName,
		Data:     rData,
		Priority: rPriority,
		Port:     rPort,
		Weight:   rWeight,
	}

	r, _, err := client.Domains.EditRecord(domainName, recordID, drcr)
	if err != nil {
		return err
	}

	return doit.DisplayOutput(r, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:60,代码来源:domains.go


示例11: RunDropletActionShutdown

// RunDropletActionShutdown shuts a droplet down.
func RunDropletActionShutdown(ns string, config doit.Config, out io.Writer, args []string) error {
	fn := func(client *godo.Client) (*godo.Action, error) {
		if len(args) != 1 {
			return nil, doit.NewMissingArgsErr(ns)
		}
		id, err := strconv.Atoi(args[0])

		a, _, err := client.DropletActions.Shutdown(id)
		return a, err
	}

	return performAction(out, config, fn)
}
开发者ID:alexcb,项目名称:doit,代码行数:14,代码来源:droplet_actions.go


示例12: RunFloatingIPActionsUnassign

// RunFloatingIPActionsUnassign unassigns a floating IP to a droplet.
func RunFloatingIPActionsUnassign(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	ip := args[0]

	client := config.GetGodoClient()

	action, _, err := client.FloatingIPActions.Unassign(ip)
	if err != nil {
		logrus.WithField("err", err).Fatal("could not unsassign IP to droplet")
	}
	return doit.DisplayOutput(action, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:16,代码来源:floating_ip_actions.go


示例13: RunImagesDelete

// RunImagesDelete deletes an image.
func RunImagesDelete(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	id, err := strconv.Atoi(args[0])
	if err != nil {
		return err
	}

	_, err = client.Images.Delete(id)
	return err
}
开发者ID:alexcb,项目名称:doit,代码行数:16,代码来源:images.go


示例14: RunDomainDelete

// RunDomainDelete deletes a domain by name.
func RunDomainDelete(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}
	name := args[0]

	client := config.GetGodoClient()

	if len(name) < 1 {
		return errors.New("invalid domain name")
	}

	_, err := client.Domains.Delete(name)
	return err
}
开发者ID:alexcb,项目名称:doit,代码行数:16,代码来源:domains.go


示例15: RunRecordDelete

// RunRecordDelete deletes a domain record.
func RunRecordDelete(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}
	domainName := args[0]

	client := config.GetGodoClient()

	recordID, err := config.GetInt(ns, doit.ArgRecordID)
	if err != nil {
		return err
	}

	_, err = client.Domains.DeleteRecord(domainName, recordID)
	return err
}
开发者ID:alexcb,项目名称:doit,代码行数:17,代码来源:domains.go


示例16: RunDropletActionEnablePrivateNetworking

// RunDropletActionEnablePrivateNetworking enables private networking for a droplet.
func RunDropletActionEnablePrivateNetworking(ns string, config doit.Config, out io.Writer, args []string) error {
	fn := func(client *godo.Client) (*godo.Action, error) {
		if len(args) != 1 {
			return nil, doit.NewMissingArgsErr(ns)
		}
		id, err := strconv.Atoi(args[0])

		if err != nil {
			return nil, err
		}

		a, _, err := client.DropletActions.EnablePrivateNetworking(id)
		return a, err
	}

	return performAction(out, config, fn)
}
开发者ID:alexcb,项目名称:doit,代码行数:18,代码来源:droplet_actions.go


示例17: RunDomainGet

// RunDomainGet retrieves a domain by name.
func RunDomainGet(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}
	id := args[0]

	client := config.GetGodoClient()

	if len(id) < 1 {
		return errors.New("invalid domain name")
	}

	d, _, err := client.Domains.Get(id)
	if err != nil {
		return err
	}

	return doit.DisplayOutput(d, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:20,代码来源:domains.go


示例18: RunKeyDelete

// RunKeyDelete deletes a key.
func RunKeyDelete(ns string, config doit.Config, out io.Writer, args []string) error {
	client := config.GetGodoClient()

	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	rawKey := args[0]

	var err error

	if i, aerr := strconv.Atoi(rawKey); aerr == nil {
		_, err = client.Keys.DeleteByID(i)
	} else {
		_, err = client.Keys.DeleteByFingerprint(rawKey)
	}

	return err
}
开发者ID:alexcb,项目名称:doit,代码行数:20,代码来源:sshkeys.go


示例19: RunCmdActionGet

// RunCmdActionGet runs action get.
func RunCmdActionGet(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	id, err := strconv.Atoi(args[0])
	if err != nil {
		return err
	}

	client := config.GetGodoClient()

	a, _, err := client.Actions.Get(id)
	if err != nil {
		return err
	}

	return doit.DisplayOutput(a, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:20,代码来源:actions.go


示例20: RunFloatingIPActionsGet

// RunFloatingIPActionsGet retrieves an action for a floating IP.
func RunFloatingIPActionsGet(ns string, config doit.Config, out io.Writer, args []string) error {
	if len(args) != 1 {
		return doit.NewMissingArgsErr(ns)
	}

	ip := args[0]

	client := config.GetGodoClient()

	actionID, err := config.GetInt(ns, doit.ArgActionID)
	if err != nil {
		return err
	}

	action, _, err := client.FloatingIPActions.Get(ip, actionID)
	if err != nil {
		return err
	}

	return doit.DisplayOutput(action, out)
}
开发者ID:alexcb,项目名称:doit,代码行数:22,代码来源:floating_ip_actions.go



注:本文中的github.com/bryanl/doit.NewMissingArgsErr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang doit.Config类代码示例发布时间:2022-05-24
下一篇:
Golang doit.DisplayOutput函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap