-
Notifications
You must be signed in to change notification settings - Fork 0
/
jrnl.go
131 lines (111 loc) · 2.91 KB
/
jrnl.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"fmt"
"os"
"os/exec"
"github.com/urfave/cli"
)
var app = cli.NewApp()
func info() {
app.Name = "Journeling CLI App"
app.Usage = "To automate the process of creating directory and daily log files, with the help of some custom written powershell scripts"
app.Author = "Abhishek K K - The Ronin"
app.Version = "1.5.0"
}
func commands() {
var projectname string
var filename string
var flag string
app.Commands = []cli.Command{
{
Name: "init",
Aliases: []string{"i", "in"},
Usage: "Initializes a journel for a project, creates a directory, and create a markdown file and open it in vscode to edit",
Action: func(c *cli.Context) {
if c.Args().First() != "" {
projectname = c.Args().First()
}
out, err := exec.Command("cmd", "/c", "powershell", "init", projectname).Output()
if err != nil {
fmt.Println("\"jrnl init\" not working")
} else {
fmt.Println(string(out))
}
},
},
{
Name: "write",
Aliases: []string{"wr", "w", "edit"},
Usage: "To write or edit daily logs",
Action: func(c *cli.Context) {
if c.Args().First() != "" {
projectname = c.Args().First()
}
out, err := exec.Command("cmd", "/c", "powershell", "record", projectname).Output()
if err != nil {
fmt.Println("\"jrnl write\" not working")
} else {
fmt.Println(string(out))
}
},
},
{
Name: "show",
Aliases: []string{"sh", "s"},
Usage: "To to show the content of project directory",
Action: func(c *cli.Context) {
if c.Args().First() != "" {
projectname = c.Args().First()
}
out, err := exec.Command("cmd", "/c", "powershell", "show", projectname).Output()
if err != nil {
fmt.Println("\"jrnl show\" not working")
} else {
fmt.Println(string(out))
}
},
},
{
Name: "log",
Aliases: []string{"lg", "l"},
Usage: "To display the content of each markdown files",
Action: func(c *cli.Context) {
if c.Args().First() != "" {
projectname = c.Args().First()
}
out, err := exec.Command("cmd", "/c", "powershell", "log", projectname).Output()
if err != nil {
fmt.Println("\"jrnl log\" not working")
} else {
fmt.Println(string(out))
}
},
},
{
Name: "open",
Aliases: []string{"op", "o"},
Usage: "To display the content of each markdown files",
Action: func(c *cli.Context) {
if (c.Args().Get(0) != "") && (c.Args().Get(1) != "") && (c.Args().Get(2) != "") {
projectname = c.Args().Get(0)
filename = c.Args().Get(1)
flag = c.Args().Get(2)
}
out, err := exec.Command("cmd", "/c", "powershell", "open", projectname, filename, flag).Output()
if err != nil {
fmt.Println("\"jrnl open\" not working")
} else {
fmt.Println(string(out))
}
},
},
}
}
func main() {
info()
commands()
err := app.Run(os.Args)
if err != nil {
fmt.Printf("Cli app not working...")
}
}