forked from keybase/client
/
cmd_favorite.go
62 lines (54 loc) · 1.56 KB
/
cmd_favorite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"fmt"
"path/filepath"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
func NewCmdFavorite(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "favorite",
ArgumentHelp: "[arguments...]",
Usage: "Manage favorites",
Subcommands: []cli.Command{
NewCmdFavoriteAdd(cl, g),
NewCmdFavoriteRemove(cl),
NewCmdFavoriteList(cl),
},
}
}
// ParseTLF takes keybase paths like
//
// /keybase/public/patrick,chris
// /keybase/private/patrick,maxtaco@twitter
// /keybase/team/bostonredsox
// public/patrick,jack
// /public/patrick,chris,sam
//
// and creates suitable folders with the name portion and the
// private flag set correctly.
func ParseTLF(path string) (keybase1.Folder, error) {
dir, name := filepath.Split(path)
var f keybase1.Folder
// get the last element of the directory, which should be public or private
acc := filepath.Base(dir)
switch acc {
case "public":
f.Private = false
f.FolderType = keybase1.FolderType_PUBLIC
case "private":
f.Private = true
f.FolderType = keybase1.FolderType_PRIVATE
case "team":
f.Private = true
f.FolderType = keybase1.FolderType_TEAM
default:
return f, fmt.Errorf("folder path needs to contain a public, private, or team subdirectory")
}
f.Name = name
return f, nil
}