-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (71 loc) · 1.61 KB
/
main.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
package main
import (
"fmt"
"github.com/fatih/color"
"log"
"os"
"github.com/urfave/cli/v2"
// "runtime"
)
func main() {
app := &cli.App{
Commands: []*cli.Command{
{
Name: "help",
Aliases: []string{"h"},
Usage: "shows you help stuff.",
Action: func (*cli.Context) error {
c := color.New(color.FgGreen, color.Bold)
fmt.Printf("Need help - ")
c.Printf("https://to.abku.dev/cli-help")
return nil
},
},
{
Name: "create",
Aliases: []string{"c"},
Usage: "create a new file with given file-type.",
Action: func(c *cli.Context) error {
filename := c.Args().First()
if filename == "" {
c := color.New(color.FgRed, color.Bold)
c.Println("please give a filename");
return nil
}
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()
success := color.New(color.FgGreen, color.Bold)
success.Printf("created file %s successfully.\n", filename)
return nil
},
},
{
Name: "remove",
Aliases: []string{"r"},
Usage: "remove a existing file with file-name.",
Action: func(c *cli.Context) error {
filename := c.Args().First()
if filename == "" {
c := color.New(color.FgRed, color.Bold)
c.Println("please give a filename");
return nil
}
err := os.Remove(filename)
if err != nil {
return err
}
success := color.New(color.FgGreen, color.Bold)
success.Printf("deleted file %s successfully.\n", filename)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
// "C:\Users\Abhishek\abku-cli\abku.exe"