-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlist.go
More file actions
32 lines (29 loc) · 712 Bytes
/
list.go
File metadata and controls
32 lines (29 loc) · 712 Bytes
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
package cmd
import (
"os"
"fmt"
"bufio"
"github.com/spf13/cobra"
)
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "Display the list of all of your bookmarks",
Long: `Display the list of all of your bookmarks`,
Run: func(cmd *cobra.Command, args []string) {
homeDir, _ := os.UserHomeDir()
if _, err := os.Stat(homeDir + "/.bookmarks/bookmarks.txt"); os.IsNotExist(err) {
fmt.Println("Your bookmarks list is empty")
return
}
f, _ := os.Open(homeDir + "/.bookmarks/bookmarks.txt")
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
fmt.Println(">", scanner.Text())
}
},
}
func init() {
rootCmd.AddCommand(listCmd)
}