chore: fix mise envs panel
This commit is contained in:
@@ -96,3 +96,24 @@ func (c *MiseController) UseGlobal(ctx *gin.Context) {
|
||||
}
|
||||
utils.Success(ctx, nil)
|
||||
}
|
||||
|
||||
// UnsetGlobal 取消全局默认版本
|
||||
func (c *MiseController) UnsetGlobal(ctx *gin.Context) {
|
||||
var req struct {
|
||||
Plugin string `json:"plugin"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
utils.BadRequest(ctx, "参数错误: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Plugin == "" {
|
||||
utils.BadRequest(ctx, "参数 plugin 不能为空")
|
||||
return
|
||||
}
|
||||
if err := c.service.UnsetGlobal(req.Plugin, req.Version); err != nil {
|
||||
utils.ServerError(ctx, "取消全局版本失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
utils.Success(ctx, nil)
|
||||
}
|
||||
|
||||
@@ -211,6 +211,7 @@ func registerMiseRoutes(g *gin.RouterGroup, c *Controllers) {
|
||||
mise.GET("/versions", c.Mise.Versions)
|
||||
mise.GET("/verify-cmd", c.Mise.VerifyCommand)
|
||||
mise.POST("/use-global", c.Mise.UseGlobal)
|
||||
mise.POST("/unset-global", c.Mise.UnsetGlobal)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -340,3 +340,19 @@ func (s *MiseService) UseGlobal(plugin, version string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnsetGlobal 取消全局默认版本
|
||||
func (s *MiseService) UnsetGlobal(plugin, version string) error {
|
||||
// 使用 mise unuse -g <tool>@<version> 移出全局配置
|
||||
target := plugin
|
||||
if version != "" {
|
||||
target = fmt.Sprintf("%s@%s", plugin, version)
|
||||
}
|
||||
cmd := exec.Command("mise", "unuse", "-g", target)
|
||||
cmd.Env = os.Environ()
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("mise unuse global failed: %v, output: %s", err, string(output))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user