-
Notifications
You must be signed in to change notification settings - Fork 5
/
snp.go
51 lines (34 loc) · 906 Bytes
/
snp.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
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/kirsle/configdir"
)
// VERSION code
const VERSION = "v0.2.0"
func main() {
// cwd, _ := os.Getwd()
// output path, default is current file
// outputPath := flag.String("o", cwd, "Where to output the snippet")
shouldPrint := flag.Bool("p", false, "Should print out the json text")
autoUpdate := flag.Bool("u", false, "Should automatically update snippet file in VS Code")
printVersion := flag.Bool("v", false, "Print version")
flag.Parse()
if *printVersion {
fmt.Println(VERSION)
os.Exit(0)
}
json := ParseSnpFiles()
if *shouldPrint {
fmt.Println(string(json))
}
if *autoUpdate {
configPath := configdir.LocalConfig("Code")
target := filepath.Join(configPath, "User", "snippets", "snp.code-snippets")
fmt.Println("Updated to", target)
ioutil.WriteFile(target, json, 0644)
}
}