本文整理汇总了Golang中github.com/disorganizer/brig/daemon.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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())
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}