[fix] fix bugs on gen-ide-env cmd.

This commit is contained in:
chengsiyuan 2024-11-20 18:38:59 +08:00
parent 2b21e934e7
commit 38866b832d

View File

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"sylixos-uploader/detector"
@ -41,14 +42,15 @@ Generate environment variables from IDE projects.`,
s := detector.NewSylixOSPrj(path)
if s.IsSylixOSPrj() {
// 输出结果
fmt.Printf("export WORKSPACE_%s=%s\n", envVarName, path)
absPath, err := filepath.Abs(relativePath)
if err != nil {
return err
}
fmt.Printf("export WORKSPACE_%s=%s\n", envVarName, absPath)
if strings.Contains(relativePath, "-") {
fmt.Printf("echo \"you have to change \\$(WORKSPACE_%s) to \\$(WORKSPACE_%s) in all config.mk\"\n", envVarNameOrgin, envVarName)
}
}
// 阻止深入子目录
return filepath.SkipDir
}
return nil
})
@ -59,9 +61,26 @@ Generate environment variables from IDE projects.`,
},
}
func init() {
RootCmd.AddCommand(genIdeEnvCmd)
// Adding flags with long names
genIdeEnvCmd.Flags().StringVar(&WorkSpacePath, "workspace", "", "Workspace path")
var fakeGenIdeEnvCmd = &cobra.Command{
Use: "gen-ide-env",
Short: "usage: source <(sylixos-uploader gen-ide-env --workspace <path>)",
Long: `usage: source <(sylixos-uploader gen-ide-env --workspace <path>)`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("This command is not supported on %s platform.\n", runtime.GOOS)
},
}
func init() {
switch runtime.GOOS {
case "linux", "darwin":
RootCmd.AddCommand(genIdeEnvCmd)
// Adding flags with long names
genIdeEnvCmd.Flags().StringVar(&WorkSpacePath, "workspace", "", "Workspace path")
default:
RootCmd.AddCommand(fakeGenIdeEnvCmd)
// Adding flags with long names
fakeGenIdeEnvCmd.Flags().StringVar(&WorkSpacePath, "workspace", "", "Workspace path")
}
}