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

Golang daemon.Client类代码示例

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

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



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

示例1: handleDebugExport

func handleDebugExport(ctx *cli.Context, client *daemon.Client) error {
	who := ctx.Args().First()

	var whoID id.ID

	if who != "" {
		validID, err := id.Cast(who)
		if err != nil {
			return err
		}

		whoID = validID
	}

	data, err := client.Export(whoID)
	if err != nil {
		return err
	}

	if _, err := os.Stdout.Write(data); err != nil {
		return err
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:25,代码来源:handlers.go


示例2: handleCommit

func handleCommit(ctx *cli.Context, client *daemon.Client) error {
	message := ctx.String("message")
	if message == "" {
		message = fmt.Sprintf("Update on %s", time.Now().String())
	}
	status, err := client.Status()
	if err != nil {
		return err
	}

	statusCmt := status.Commit
	if statusCmt == nil {
		return fmt.Errorf("Empty status commit in response.")
	}

	commitCnt := len(statusCmt.Changeset)
	if commitCnt == 0 {
		fmt.Println("Nothing to commit.")
		return nil
	}
	if commitCnt != 1 {
		fmt.Printf("%d changes commited.\n", commitCnt)
	} else {
		fmt.Printf("%d change commited.\n", commitCnt)
	}

	return client.MakeCommit(message)
}
开发者ID:disorganizer,项目名称:brig,代码行数:28,代码来源:handlers.go


示例3: handleLog

func handleLog(ctx *cli.Context, client *daemon.Client) error {
	log, err := client.Log(nil, nil)
	if err != nil {
		return err
	}

	for _, pnode := range log.Nodes {
		commitMH, err := multihash.Cast(pnode.Hash)
		if err != nil {
			return err
		}

		pcmt := pnode.Commit
		if pcmt == nil {
			return fmt.Errorf("Empty commit in log-commit")
		}

		rootMH, err := multihash.Cast(pcmt.Root)
		if err != nil {
			return err
		}

		fmt.Printf(
			"%s/%s by %s, %s\n",
			colors.Colorize(commitMH.B58String()[:10], colors.Green),
			colors.Colorize(rootMH.B58String()[:10], colors.Magenta),
			pcmt.Author,
			pcmt.Message,
		)
	}
	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:32,代码来源:handlers.go


示例4: doMount

func doMount(ctx *cli.Context, client *daemon.Client, mount bool) error {
	mountPath := ""
	if len(ctx.Args()) > 0 {
		mountPath = ctx.Args().First()
	} else {
		mountPath = filepath.Join(guessRepoFolder(), "mount")
		if err := os.Mkdir(mountPath, 0744); err != nil {
			return err
		}
	}

	var err error

	if mount {
		err = client.Mount(mountPath)
	} else {
		err = client.Unmount(mountPath)
	}

	if err != nil {
		return ExitCode{UnknownError, fmt.Sprintf("fuse: %v", err)}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:25,代码来源:handlers.go


示例5: handleStage

func handleStage(ctx *cli.Context, client *daemon.Client) error {
	filePath, err := filepath.Abs(ctx.Args().First())
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Unable to make abs path: %v: %v", filePath, err),
		}
	}

	// Assume "/file.png" for file.png as repo path, if none given.
	repoPath := "/" + filepath.Base(filePath)
	if ctx.NArg() > 1 {
		repoPath = ctx.Args()[1]
	}

	if err := client.Stage(filePath, repoPath); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Could not stage file: %v: %v", filePath, err),
		}
	}

	fmt.Println(repoPath)
	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:25,代码来源:handlers.go


示例6: handleDebugImport

func handleDebugImport(ctx *cli.Context, client *daemon.Client) error {
	buf := &bytes.Buffer{}

	if _, err := io.Copy(buf, os.Stdin); err != nil {
		return err
	}

	return client.Import(buf.Bytes())
}
开发者ID:disorganizer,项目名称:brig,代码行数:9,代码来源:handlers.go


示例7: handleMv

func handleMv(ctx *cli.Context, client *daemon.Client) error {
	source, dest := prefixSlash(ctx.Args().First()), prefixSlash(ctx.Args().Get(1))

	if err := client.Move(source, dest); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("move failed: %v", err),
		}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:12,代码来源:handlers.go


示例8: handleIsOnline

func handleIsOnline(ctx *cli.Context, client *daemon.Client) error {
	status, err := client.IsOnline()
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Failed to check online-status: %v", err),
		}
	}

	fmt.Println(status)
	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:12,代码来源:handlers.go


示例9: handleRm

func handleRm(ctx *cli.Context, client *daemon.Client) error {
	repoPath := prefixSlash(ctx.Args().First())

	if err := client.Remove(repoPath, ctx.Bool("recursive")); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Could not remove file: `%s`: %v", repoPath, err),
		}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:12,代码来源:handlers.go


示例10: handleRemoteSelf

func handleRemoteSelf(ctx *cli.Context, client *daemon.Client) error {
	re, err := client.RemoteSelf()
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Unable to list remote self information: %v", err),
		}
	}

	printRemoteEntry(re)
	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:12,代码来源:remotes.go


示例11: handleRemoteList

func handleRemoteList(ctx *cli.Context, client *daemon.Client) error {
	data, err := client.RemoteList()
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Unable to list remotes: %v", err),
		}
	}
	for _, entry := range data {
		printRemoteEntry(entry)
	}
	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:13,代码来源:remotes.go


示例12: handleList

func handleList(ctx *cli.Context, client *daemon.Client) error {
	path := "/"
	if ctx.NArg() > 0 {
		path = prefixSlash(ctx.Args().First())
	}

	depth := ctx.Int("depth")
	if ctx.Bool("recursive") {
		depth = -1
	}

	entries, err := client.List(path, depth)
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("ls: %v", err),
		}
	}

	for _, entry := range entries {
		modTime := time.Time{}
		if err := modTime.UnmarshalText(entry.ModTime); err != nil {
			log.Warningf("Could not parse mtime (%s): %v", entry.ModTime, err)
			continue
		}

		fmt.Printf(
			"%s\t%s\t%s\n",
			colors.Colorize(
				humanize.Bytes(uint64(entry.NodeSize)),
				colors.Green,
			),
			colors.Colorize(
				humanize.Time(modTime),
				colors.Cyan,
			),
			colors.Colorize(
				entry.Path,
				colors.Magenta,
			),
		)
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:45,代码来源:handlers.go


示例13: handleSyncSingle

func handleSyncSingle(ctx *cli.Context, client *daemon.Client, idStr string) error {
	ID, err := id.Cast(idStr)

	if err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Bad ID: %v", err),
		}
	}

	log.Infof("Syncing with %s", ID)
	if err := client.Sync(ID); err != nil {
		log.Errorf("Failed: %v", err)
		return ExitCode{UnknownError, err.Error()}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:18,代码来源:handlers.go


示例14: handleRemoteRemove

func handleRemoteRemove(ctx *cli.Context, client *daemon.Client) error {
	idString := ctx.Args()[0]
	id, err := id.Cast(idString)
	if err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Invalid ID: %v", err),
		}
	}

	if client.RemoteRemove(id) != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Unable to remove remote: %v", err),
		}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:19,代码来源:remotes.go


示例15: handleHistory

func handleHistory(ctx *cli.Context, client *daemon.Client) error {
	repoPath := prefixSlash(ctx.Args().First())

	history, err := client.History(repoPath)
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Unable to retrieve history: %v", err),
		}
	}

	fmt.Println(colors.Colorize(repoPath, colors.Magenta))
	for idx := range history {
		checkpoint := history[len(history)-idx-1]
		printCheckpoint(checkpoint, idx, len(history))

	}
	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:19,代码来源:handlers.go


示例16: handleMkdir

func handleMkdir(ctx *cli.Context, client *daemon.Client) error {
	path := prefixSlash(ctx.Args().First())

	var err error

	if ctx.Bool("parents") {
		err = client.MkdirAll(path)
	} else {
		err = client.Mkdir(path)
	}

	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("mkdir failed: %v", err),
		}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:20,代码来源:handlers.go


示例17: handleRemoteAdd

func handleRemoteAdd(ctx *cli.Context, client *daemon.Client) error {
	idString, hash := ctx.Args()[0], ctx.Args()[1]

	id, err := id.Cast(idString)
	if err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Invalid ID: %v", err),
		}
	}

	if err := client.RemoteAdd(id, hash); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Unable to add remote: %v", err),
		}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:20,代码来源:remotes.go


示例18: handleStatus

func handleStatus(ctx *cli.Context, client *daemon.Client) error {
	status, err := client.Status()
	if err != nil {
		return err
	}

	statusCmt := status.Commit
	if statusCmt == nil {
		return fmt.Errorf("Empty status commit in response.")
	}

	checkpoints := statusCmt.Checkpoints
	if len(checkpoints) == 0 {
		fmt.Println("Nothing to commit.")
		return nil
	}

	userToChanges := make(map[id.ID]changeByType)
	for _, pckp := range checkpoints {
		byAuthor, ok := userToChanges[id.ID(pckp.Author)]
		if !ok {
			byAuthor = make(changeByType)
			userToChanges[id.ID(pckp.Author)] = byAuthor
		}

		byAuthor[pckp.Change] = append(byAuthor[pckp.Change], pckp)
	}

	for user, changesByuser := range userToChanges {
		fmt.Printf(
			"Changes by %s:\n",
			colors.Colorize(string(user), colors.Magenta),
		)
		printChangesByUser(changesByuser)
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:38,代码来源:handlers.go


示例19: handleRemoteLocate

func handleRemoteLocate(ctx *cli.Context, client *daemon.Client) error {
	id, err := id.Cast(ctx.Args()[0])
	if err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Invalid ID: %v", err),
		}
	}

	hashes, err := client.RemoteLocate(id, 10, 50000)
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Unable to locate ipfs peers: %v", err),
		}
	}

	for _, hash := range hashes {
		fmt.Println(hash)
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:23,代码来源:remotes.go


示例20: handleOnline

func handleOnline(ctx *cli.Context, client *daemon.Client) error {
	status, err := client.IsOnline()
	if err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Failed to check online-status: %v", err),
		}
	}

	if status {
		log.Infof("Already online.")
		return nil
	}

	if err := client.Online(); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Failed to go online: %v", err),
		}
	}

	return nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:23,代码来源:handlers.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang wire.Command类代码示例发布时间:2022-05-23
下一篇:
Golang imaging.Transverse函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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