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