80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/spf13/cobra"
|
||
|
"os"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
var ja *cobra.Command
|
||
|
|
||
|
func init() {
|
||
|
var vmOptionDir string
|
||
|
|
||
|
ja = &cobra.Command{
|
||
|
Use: "ja",
|
||
|
Short: "jetbrains activation",
|
||
|
Example: "ja -d C:/Users/xuthu/AppData/Roaming/JetBrains",
|
||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||
|
// create home dir
|
||
|
CreateWorkDir()
|
||
|
// download ja-netfilter
|
||
|
DownloadJaNetfilter()
|
||
|
// unzip ja-netfilter
|
||
|
UnzipJaNetfilter()
|
||
|
},
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
dirEntries, err := os.ReadDir(vmOptionDir)
|
||
|
if err != nil {
|
||
|
panic("read dir failed: " + err.Error())
|
||
|
}
|
||
|
for _, entry := range dirEntries {
|
||
|
if !entry.IsDir() {
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "CLion") {
|
||
|
InjectVmOption(entry.Name(), "clion64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "GoLand") {
|
||
|
InjectVmOption(entry.Name(), "goland64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "PyCharm") {
|
||
|
InjectVmOption(entry.Name(), "pycharm64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "WebStorm") {
|
||
|
InjectVmOption(entry.Name(), "webstorm64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "RustRover") {
|
||
|
InjectVmOption(entry.Name(), "rustrover64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "DataGrip") {
|
||
|
InjectVmOption(entry.Name(), "datagrip64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "IntelliJIdea") {
|
||
|
InjectVmOption(entry.Name(), "idea64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
if strings.Contains(entry.Name(), "PhpStorm") {
|
||
|
InjectVmOption(entry.Name(), "PhpStorm64.exe.vmoptions", vmOptionDir)
|
||
|
continue
|
||
|
}
|
||
|
}
|
||
|
|
||
|
logger.Printf("jetbrains activation success, access: https://jbls.ide-soft.com/")
|
||
|
},
|
||
|
}
|
||
|
ja.Flags().StringVarP(&vmOptionDir, "dir", "d", DefaultVmOptionDir(), "jetbrains vm option dir")
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
if err := ja.Execute(); err != nil {
|
||
|
logger.Printf("running command failed: %v", err)
|
||
|
}
|
||
|
}
|