-
Notifications
You must be signed in to change notification settings - Fork 0
/
openup.go
46 lines (34 loc) · 801 Bytes
/
openup.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
package cmd
import (
"fmt"
"os"
"bufio"
"github.com/spf13/cobra"
"github.com/pkg/browser"
)
// openupCmd represents the openup command
var openupCmd = &cobra.Command{
Use: "openup",
Short: "opens up urls",
Long:"A command to open my usual tabs and start my working day",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Rise and Shine, Start your day")
// Declare variable
pathToFile := args[0]
// Shows the path to the file and declares an error if any
file, err := os.Open(pathToFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Scan the file and opens up in browser
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
browser.OpenURL(line)
}
},
}
func init() {
rootCmd.AddCommand(openupCmd)
}