代码拉取完成,页面将自动刷新
package cmd
import (
"fmt"
"os"
"runtime"
"gitee.com/gitwcx/jenv/sdk/config"
style2 "gitee.com/gitwcx/jenv/sdk/style"
"gitee.com/gitwcx/jenv/sdk/sys"
"github.com/spf13/cobra"
)
var Version = "dev"
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "jenv",
Short: "A Java version manager",
Long: `Jenv is a command-line tool for managing multiple Java versions.
It allows you to easily switch between different Java versions,
add new Java installations, and manage your Java environment.
First time setup:
➜ Run 'jenv add-to-path' to add jenv to your system PATH
➜ Run 'jenv scan <dir>' to find and add Java installations
➜ Run 'jenv use <name>' to select a Java version`,
Version: Version,
}
func init() {
rootCmd.SetVersionTemplate(`{{with .Name}}{{printf "%s " .}}{{end}}{{printf "version %s" .Version}}
Author: WhyWhatHow (https://github.com/WhyWhatHow)
Email: whywhathow.fun@gmail.com
License: Apache License 2.0
`)
// Check admin privileges - different logic for different platforms
if runtime.GOOS == "windows" {
// Windows always requires administrator privileges
if !sys.IsAdmin() {
fmt.Printf("%s: %s\n",
style2.Error.Render("Error"),
style2.Error.Render("Administrator privileges required"))
os.Exit(1)
}
} else {
// Linux/Unix: Only warn if not root, don't exit
if !sys.IsAdmin() {
fmt.Printf("%s: %s\n",
style2.Warning.Render("Warning"),
style2.Warning.Render("Running without root privileges. Some features may be limited."))
fmt.Printf("%s: %s\n",
style2.Info.Render("Info"),
style2.Info.Render("jenv will use user-level configuration and symlinks."))
}
}
// Initialize configuration system
cfg, err := config.GetInstance()
if err != nil {
fmt.Printf("%s: %s\n%s\n",
style2.Error.Render("Error"),
style2.Error.Render("Failed to initialize configuration"),
style2.Error.Render(err.Error()))
os.Exit(1)
}
// Apply saved theme if exists
if cfg.Theme != "" {
if theme, ok := style2.GetThemeByName(cfg.Theme); ok {
style2.ApplyTheme(theme)
}
}
// Check if jenv has been initialized
if !cfg.Initialized {
fmt.Printf("%s: %s\n",
style2.Warning.Render("Warning"),
style2.Warning.Render("jenv has not been initialized yet"))
fmt.Printf("%s: %s\n",
style2.Info.Render("Info"),
style2.Info.Render("Run 'jenv init' to set up jenv for first-time use"))
fmt.Println()
}
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。