Skip to content

Commit

Permalink
Support lockfile generation for cocoapods
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Jun 20, 2024
1 parent 595f77d commit 5a93a78
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions cmd/cocoapods.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var ecosystems = []func() *cobra.Command{
npmCmd,
yarnCmd,
swiftCmd,
cocoapodsCmd,
}

func NewRootCmd() *cobra.Command {
Expand Down
5 changes: 2 additions & 3 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -39,7 +39,6 @@ func CreateLockFile(lockFiles []string, cmdArgs []string, lockGenCmd []string, o
continue
}
return

}
}
genLock(lockGenCmd, absPath, outputFileName)
Expand Down

0 comments on commit 5a93a78

Please sign in to comment.