diff --git a/cmd/utils.go b/cmd/utils.go index d02ca186..70b3c294 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -3,10 +3,14 @@ package cmd import ( "fmt" "os" + "path" "github.com/bitrise-core/bitrise-init/scanners/ios" "github.com/bitrise-core/bitrise-init/scanners/xamarin" "github.com/bitrise-core/bitrise-init/utility" + "github.com/bitrise-io/go-utils/colorstring" + "github.com/bitrise-io/go-utils/log" + "github.com/bitrise-io/goinp/goinp" ) // projectType enum. @@ -60,3 +64,73 @@ func scanForProjectFiles(projType projectType) ([]string, error) { } return paths, nil } + +// findProject scans the directory for Xcode Project (.xcworkspace / .xcodeproject) file first +// If can't find any, ask the user to drag-and-drop the file +func findXcodeProject() (string, error) { + var projpth string + + projPaths, err := scanForProjectFiles(iOSProjectType) + if err != nil { + log.Printf("Failed: %s", err) + fmt.Println() + + log.Infof("Provide the project file manually") + askText := `Please drag-and-drop your Xcode Project (` + colorstring.Green(".xcodeproj") + `) or Workspace (` + colorstring.Green(".xcworkspace") + `) file, +the one you usually open in Xcode, then hit Enter. +(Note: if you have a Workspace file you should most likely use that)` + projpth, err = goinp.AskForPath(askText) + if err != nil { + return "", fmt.Errorf("failed to read input: %s", err) + } + + return projpth, nil + } + + if len(projPaths) == 1 { + log.Printf("Found one project file: %s.", path.Base(projPaths[0])) + return projPaths[0], nil + } + + log.Printf("Found multiple project file: %s.", path.Base(projpth)) + projpth, err = goinp.SelectFromStringsWithDefault("Select the project file you want to scan", 1, projPaths) + if err != nil { + return "", fmt.Errorf("failed to select project file: %s", err) + } + + return projpth, nil +} + +// findSolution scans the directory for Xamarin.Solution file first +// If can't find any, ask the user to drag-and-drop the file +func findXamarinSolution() (string, error) { + var solutionPth string + solPaths, err := scanForProjectFiles(xamarinProjectType) + if err != nil { + log.Printf("Failed: %s", err) + fmt.Println() + + log.Infof("Provide the solution file manually") + askText := `Please drag-and-drop your Xamarin Solution (` + colorstring.Green(".sln") + `) file, +and then hit Enter` + solutionPth, err = goinp.AskForPath(askText) + if err != nil { + return "", fmt.Errorf("failed to read input: %s", err) + } + + return solutionPth, nil + } + + if len(solPaths) == 1 { + log.Printf("Found one solution file: %s.", path.Base(solPaths[0])) + return solPaths[0], nil + } + + log.Printf("Found multiple solution file: %s.", path.Base(solutionPth)) + solutionPth, err = goinp.SelectFromStringsWithDefault("Select the solution file you want to scan", 1, solPaths) + if err != nil { + return "", fmt.Errorf("failed to select solution file: %s", err) + } + + return solutionPth, nil +} diff --git a/cmd/xamarin.go b/cmd/xamarin.go index 76c454c3..5849e63e 100644 --- a/cmd/xamarin.go +++ b/cmd/xamarin.go @@ -3,7 +3,6 @@ package cmd import ( "encoding/json" "fmt" - "path" "path/filepath" "sort" @@ -76,38 +75,6 @@ func archivableSolutionConfigNames(projectsByID map[string]project.Model) []stri return archivableSolutionConfigNames } -// findSolution scans the directory for Xamarin.Solution file first -// If can't find any, ask the user to drag-and-drop the file -func findSolution() (string, error) { - var solutionPth string - solPaths, err := scanForProjectFiles(xamarinProjectType) - if err != nil { - log.Printf("Failed: %s", err) - fmt.Println() - - log.Infof("Provide the solution file manually") - askText := `Please drag-and-drop your Xamarin Solution (` + colorstring.Green(".sln") + `) file, -and then hit Enter` - solutionPth, err = goinp.AskForPath(askText) - if err != nil { - return "", fmt.Errorf("failed to read input: %s", err) - } - } else { - if len(solPaths) == 1 { - log.Printf("Found one solution file: %s.", path.Base(solPaths[0])) - solutionPth = solPaths[0] - } else { - log.Printf("Found multiple solution file: %s.", path.Base(solutionPth)) - solutionPth, err = goinp.SelectFromStringsWithDefault("Select the solution file you want to scan", 1, solPaths) - if err != nil { - return "", fmt.Errorf("failed to select solution file: %s", err) - } - } - } - - return solutionPth, nil -} - func scanXamarinProject(cmd *cobra.Command, args []string) error { absExportOutputDirPath, err := initExportOutputDir() if err != nil { @@ -127,7 +94,7 @@ func scanXamarinProject(cmd *cobra.Command, args []string) error { // // Scan the directory for Xamarin.Solution file first // If can't find any, ask the user to drag-and-drop the file - xamarinCmd.SolutionFilePath, err = findSolution() + xamarinCmd.SolutionFilePath, err = findXamarinSolution() if err != nil { return err } diff --git a/cmd/xcode.go b/cmd/xcode.go index 9c000445..ffe08a99 100644 --- a/cmd/xcode.go +++ b/cmd/xcode.go @@ -3,7 +3,6 @@ package cmd import ( "fmt" "os" - "path" "path/filepath" "strings" @@ -62,41 +61,6 @@ func initExportOutputDir() (string, error) { return absExportOutputDirPath, nil } -// findProject scans the directory for Xcode Project (.xcworkspace / .xcodeproject) file first -// If can't find any, ask the user to drag-and-drop the file -func findProject() (string, error) { - var projpth string - - projPaths, err := scanForProjectFiles(iOSProjectType) - if err != nil { - log.Printf("Failed: %s", err) - fmt.Println() - - log.Infof("Provide the project file manually") - askText := `Please drag-and-drop your Xcode Project (` + colorstring.Green(".xcodeproj") + `) or Workspace (` + colorstring.Green(".xcworkspace") + `) file, -the one you usually open in Xcode, then hit Enter. -(Note: if you have a Workspace file you should most likely use that)` - projpth, err = goinp.AskForPath(askText) - if err != nil { - return "", fmt.Errorf("failed to read input: %s", err) - } - return projpth, err - } - - if len(projPaths) == 1 { - log.Printf("Found one project file: %s.", path.Base(projPaths[0])) - return projPaths[0], nil - } - - log.Printf("Found multiple project file: %s.", path.Base(projpth)) - projpth, err = goinp.SelectFromStringsWithDefault("Select the project file you want to scan", 1, projPaths) - if err != nil { - return "", fmt.Errorf("failed to select project file: %s", err) - } - - return projpth, nil -} - func scanXcodeProject(cmd *cobra.Command, args []string) error { absExportOutputDirPath, err := initExportOutputDir() if err != nil { @@ -120,14 +84,14 @@ func scanXcodeProject(cmd *cobra.Command, args []string) error { log.Infof("Scan the directory for project files") log.Warnf("You can specify the Xcode project/workscape file to scan with the --file flag.") - projpth, err := findProject() + // + // Scan the directory for Xcode Project (.xcworkspace / .xcodeproject) file first + // If can't find any, ask the user to drag-and-drop the file + projpth, err := findXcodeProject() if err != nil { return err } - // - // Scan the directory for Xcode Project (.xcworkspace / .xcodeproject) file first - // If can't find any, ask the user to drag-and-drop the file projectPath = strings.Trim(strings.TrimSpace(projpth), "'\"") } log.Debugf("projectPath: %s", projectPath) diff --git a/cmd/xcodeUITests.go b/cmd/xcodeUITests.go index ccd8b440..4f2e789b 100644 --- a/cmd/xcodeUITests.go +++ b/cmd/xcodeUITests.go @@ -50,18 +50,20 @@ func scanXcodeUITestsProject(cmd *cobra.Command, args []string) error { projectPath := paramXcodeProjectFilePath if projectPath == "" { - askText := `Please drag-and-drop your Xcode Project (` + colorstring.Green(".xcodeproj") + `) or Workspace (` + colorstring.Green(".xcworkspace") + `) file, -the one you usually open in Xcode, then hit Enter. -(Note: if you have a Workspace file you should most likely use that)` - projpth, err := goinp.AskForPath(askText) + log.Infof("Scan the directory for project files") + log.Warnf("You can specify the Xcode project/workscape file to scan with the --file flag.") + + // + // Scan the directory for Xcode Project (.xcworkspace / .xcodeproject) file first + // If can't find any, ask the user to drag-and-drop the file + projpth, err := findXcodeProject() if err != nil { - return fmt.Errorf("failed to read input: %s", err) + return err } projectPath = strings.Trim(strings.TrimSpace(projpth), "'\"") } log.Debugf("projectPath: %s", projectPath) - xcodeUITestsCmd := xcodeuitest.CommandModel{ProjectFilePath: projectPath} schemeToUse := paramXcodeScheme