-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (74 loc) · 1.67 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
83
84
85
86
87
88
89
90
91
92
package main
import (
"errors"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"uzo/util"
"github.com/spf13/cobra"
)
var(
File string
// dest string
)
var rootCmd = &cobra.Command{
Use: "uzo command to unzip and open with code",
Short: "Unzipping application",
Args: func(cmd *cobra.Command, args []string) error {
if File == "" && len(args) < 1 {
return errors.New("accepts 1 arg(s)")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(File)
var filename string
var err error
var argument string
if File != "" {
argument = File
} else {
argument = args[0]
}
fileExists, err := util.FileExists(argument)
if err != nil {
fmt.Println(err)
}
if fileExists {
filename, err = filepath.Abs(argument)
if err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Printf("File %v doest not Exists", argument)
return
}
wd, err := os.Getwd()
if err != nil {
fmt.Println(err.Error())
}
util.Unzip(filename, wd)
os.Chdir(util.FilenameWithoutExtension(filename))
wd, err = os.Getwd()
if err != nil {
fmt.Println(err)
}
commandCode := exec.Command("code", wd)
err = commandCode.Run()
if err != nil {
log.Fatal("VS Code executable file not found in %PATH%")
}
},
}
// func init() {
// rootCmd.PersistentFlags().StringVarP(&dest, "dest", "d", "", "Pass a destination where you want to copy")
// rootCmd.PersistentFlags().StringVarP(&source, "source", "s", "", "Pass a Source from where you want to copy")
// }
func main() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}