Skip to content

Commit 5a93a78

Browse files
committed
Support lockfile generation for cocoapods
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 595f77d commit 5a93a78

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Supported Ecosystems
3131
- **pnpm**: https://pnpm.io/
3232
- **yarn**: https://yarnpkg.com/
3333
- **swift**: https://www.swift.org/documentation/package-manager/
34+
- **cocoapods**: https://cocoapods.org/
3435

3536

3637
Installation

cmd/cocoapods.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
3+
Copyright (c) nexB Inc. and others. All rights reserved.
4+
ScanCode is a trademark of nexB Inc.
5+
SPDX-License-Identifier: Apache-2.0
6+
See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
7+
See https://github.com/nexB/dependency-inspector for support or download.
8+
See https://aboutcode.org for more information about nexB OSS projects.
9+
10+
*/
11+
12+
package cmd
13+
14+
import (
15+
"github.com/nexB/dependency-inspector/internal"
16+
"github.com/spf13/cobra"
17+
)
18+
19+
func cocoapodsCmd() *cobra.Command {
20+
lockFiles := []string{"Podfile.lock"}
21+
lockGenCommand := []string{"pod", "install"}
22+
forced := false
23+
24+
cocoapodsCmd := &cobra.Command{
25+
Use: "cocoapods [path]",
26+
Short: "Generate lockfile for cocoapods project",
27+
Long: `Create lockfile for cocoapods project if it doesn't exist in the specified [path].
28+
If no path is provided, the command defaults to the current directory.`,
29+
Args: cobra.MaximumNArgs(1),
30+
Run: func(cmd *cobra.Command, args []string) {
31+
internal.CreateLockFile(
32+
lockFiles,
33+
args,
34+
lockGenCommand,
35+
"",
36+
forced,
37+
)
38+
},
39+
}
40+
41+
cocoapodsCmd.Flags().BoolVarP(&forced, "force", "f", false, "Generate lockfile forcibly, ignoring existing lockfiles")
42+
43+
return cocoapodsCmd
44+
}

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var ecosystems = []func() *cobra.Command{
2323
npmCmd,
2424
yarnCmd,
2525
swiftCmd,
26+
cocoapodsCmd,
2627
}
2728

2829
func NewRootCmd() *cobra.Command {

internal/utils.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func CreateLockFile(lockFiles []string, cmdArgs []string, lockGenCmd []string, o
2727

2828
absPath, err := filepath.Abs(path)
2929
if err != nil {
30-
fmt.Fprintf(os.Stderr, "Error: Failed to retrieve absolute path: %v\n", err)
31-
os.Exit(1)
30+
fmt.Fprintln(os.Stderr, "Error: Failed to retrieve absolute path: ", err)
31+
return
3232
}
3333

3434
if !forced {
@@ -39,7 +39,6 @@ func CreateLockFile(lockFiles []string, cmdArgs []string, lockGenCmd []string, o
3939
continue
4040
}
4141
return
42-
4342
}
4443
}
4544
genLock(lockGenCmd, absPath, outputFileName)

0 commit comments

Comments
 (0)