ja/main.go

80 lines
2.0 KiB
Go
Raw Permalink Normal View History

2024-07-28 05:58:14 +00:00
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") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "clion64", vmOptionDir)
2024-07-28 05:58:14 +00:00
continue
}
if strings.Contains(entry.Name(), "GoLand") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "goland64", vmOptionDir)
2024-07-28 05:58:14 +00:00
continue
}
if strings.Contains(entry.Name(), "PyCharm") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "pycharm64", vmOptionDir)
2024-07-28 05:58:14 +00:00
continue
}
if strings.Contains(entry.Name(), "WebStorm") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "webstorm64", vmOptionDir)
2024-07-28 05:58:14 +00:00
continue
}
if strings.Contains(entry.Name(), "RustRover") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "rustrover64", vmOptionDir)
2024-07-28 05:58:14 +00:00
continue
}
if strings.Contains(entry.Name(), "DataGrip") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "datagrip64", vmOptionDir)
2024-07-28 05:58:14 +00:00
continue
}
if strings.Contains(entry.Name(), "IntelliJIdea") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "idea64", vmOptionDir)
2024-07-28 05:58:14 +00:00
continue
}
if strings.Contains(entry.Name(), "PhpStorm") {
2024-07-28 06:11:45 +00:00
InjectVmOption(entry.Name(), "PhpStorm64", vmOptionDir)
2024-07-28 05:58:14 +00:00
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)
}
}