diff --git a/README.rst b/README.rst index bc4bc47..0e89a28 100644 --- a/README.rst +++ b/README.rst @@ -31,6 +31,7 @@ Supported Ecosystems - **pnpm**: https://pnpm.io/ - **yarn**: https://yarnpkg.com/ - **swift**: https://www.swift.org/documentation/package-manager/ +- **cocoapods**: https://cocoapods.org/ Installation diff --git a/cmd/cocoapods.go b/cmd/cocoapods.go new file mode 100644 index 0000000..cefc920 --- /dev/null +++ b/cmd/cocoapods.go @@ -0,0 +1,44 @@ +/* + +Copyright (c) nexB Inc. and others. All rights reserved. +ScanCode is a trademark of nexB Inc. +SPDX-License-Identifier: Apache-2.0 +See http://www.apache.org/licenses/LICENSE-2.0 for the license text. +See https://github.com/nexB/dependency-inspector for support or download. +See https://aboutcode.org for more information about nexB OSS projects. + +*/ + +package cmd + +import ( + "github.com/nexB/dependency-inspector/internal" + "github.com/spf13/cobra" +) + +func cocoapodsCmd() *cobra.Command { + lockFiles := []string{"Podfile.lock"} + lockGenCommand := []string{"pod", "install"} + forced := false + + cocoapodsCmd := &cobra.Command{ + Use: "cocoapods [path]", + Short: "Generate lockfile for cocoapods project", + Long: `Create lockfile for cocoapods project if it doesn't exist in the specified [path]. +If no path is provided, the command defaults to the current directory.`, + Args: cobra.MaximumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + internal.CreateLockFile( + lockFiles, + args, + lockGenCommand, + "", + forced, + ) + }, + } + + cocoapodsCmd.Flags().BoolVarP(&forced, "force", "f", false, "Generate lockfile forcibly, ignoring existing lockfiles") + + return cocoapodsCmd +} diff --git a/cmd/root.go b/cmd/root.go index 9eb3039..e6a927f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,6 +23,7 @@ var ecosystems = []func() *cobra.Command{ npmCmd, yarnCmd, swiftCmd, + cocoapodsCmd, } func NewRootCmd() *cobra.Command { diff --git a/internal/utils.go b/internal/utils.go index a657236..161c5e3 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -27,8 +27,8 @@ func CreateLockFile(lockFiles []string, cmdArgs []string, lockGenCmd []string, o absPath, err := filepath.Abs(path) if err != nil { - fmt.Fprintf(os.Stderr, "Error: Failed to retrieve absolute path: %v\n", err) - os.Exit(1) + fmt.Fprintln(os.Stderr, "Error: Failed to retrieve absolute path: ", err) + return } if !forced { @@ -39,7 +39,6 @@ func CreateLockFile(lockFiles []string, cmdArgs []string, lockGenCmd []string, o continue } return - } } genLock(lockGenCmd, absPath, outputFileName)