diff --git a/cmd/gen_ide_env.go b/cmd/gen_ide_env.go index 4146c96..87944cb 100644 --- a/cmd/gen_ide_env.go +++ b/cmd/gen_ide_env.go @@ -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 )", + Long: `usage: source <(sylixos-uploader gen-ide-env --workspace )`, + 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") + } }