Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions completers/common/pnpm_completer/cmd/catFile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var catFileCmd = &cobra.Command{
Use: "cat-file",
Short: "Prints the contents of a file based on the hash value stored in the index file",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(catFileCmd).Standalone()

catFileCmd.Flags().BoolP("help", "h", false, "Output usage information")

rootCmd.AddCommand(catFileCmd)
}
20 changes: 20 additions & 0 deletions completers/common/pnpm_completer/cmd/catIndex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var catIndexCmd = &cobra.Command{
Use: "cat-index",
Short: "Prints the index file of a specific package from the store",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(catIndexCmd).Standalone()

catIndexCmd.Flags().BoolP("help", "h", false, "Output usage information")

rootCmd.AddCommand(catIndexCmd)
}
40 changes: 31 additions & 9 deletions completers/common/pnpm_completer/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,46 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bridge/pkg/actions/bridge"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/pnpm"
"github.com/spf13/cobra"
)

var execCmd = &cobra.Command{
Use: "exec",
Short: "Executes a shell command in scope of a project",
GroupID: "run",
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagParsing: true,
Use: "exec",
Short: "Executes a shell command in scope of a project",
GroupID: "run",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(execCmd).Standalone()

execCmd.Flags().Bool("aggregate-output", false, "Aggregate output from child processes that are run in parallel")
execCmd.Flags().String("changed-files-ignore-pattern", "", "Defines files to ignore when filtering for changed projects")
execCmd.Flags().Bool("color", false, "Controls colors in the output")
execCmd.Flags().StringP("dir", "C", "", "Change to directory <dir>")
execCmd.Flags().String("filter", "", "set filter")
execCmd.Flags().String("filter-prod", "", "Restricts the scope to package names matching the given pattern")
execCmd.Flags().BoolP("help", "h", false, "Output usage information")
execCmd.Flags().String("loglevel", "", "What level of logs to report")
execCmd.Flags().Bool("no-bail", false, "The command will exit with a 0 exit code even if the script fails")
execCmd.Flags().Bool("no-color", false, "Controls colors in the output")
execCmd.Flags().Bool("parallel", false, "Completely disregard concurrency and topological sorting")
execCmd.Flags().BoolP("recursive", "r", false, "Run the defined package script in every package found in subdirectories")
execCmd.Flags().Bool("report-summary", false, "Save the execution results of every package to \"pnpm-exec-summary.json\"")
execCmd.Flags().Bool("resume-from", false, "Command executed from given package")
execCmd.Flags().Bool("sequential", false, "Run the specified scripts one by one")
execCmd.Flags().Bool("stream", false, "Stream output from child processes immediately")
execCmd.Flags().String("test-pattern", "", "Defines files related to tests.")
execCmd.Flags().Bool("use-stderr", false, "Divert all output to stderr")
execCmd.Flags().Bool("workspace-root", false, "Run the command on the root workspace project")
addWorkspaceFlags(execCmd)
rootCmd.AddCommand(execCmd)

carapace.Gen(execCmd).PositionalAnyCompletion(
bridge.ActionCarapaceBin(),
)
carapace.Gen(execCmd).FlagCompletion(carapace.ActionMap{
"dir": carapace.ActionDirectories(),
"filter": pnpm.ActionFilter(),
"filter-prod": pnpm.ActionFilter(),
"loglevel": pnpm.ActionLoglevel(),
})
}
20 changes: 20 additions & 0 deletions completers/common/pnpm_completer/cmd/findHash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var findHashCmd = &cobra.Command{
Use: "find-hash",
Short: "Experimental! Lists the packages that include the file with the specified hash",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(findHashCmd).Standalone()

findHashCmd.Flags().BoolP("help", "h", false, "Output usage information")

rootCmd.AddCommand(findHashCmd)
}
20 changes: 20 additions & 0 deletions completers/common/pnpm_completer/cmd/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var helpCmd = &cobra.Command{
Use: "help",
Short: "Show help for pnpm",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(helpCmd).Standalone()

helpCmd.Flags().BoolP("help", "h", false, "Output usage information")

rootCmd.AddCommand(helpCmd)
}
28 changes: 28 additions & 0 deletions completers/common/pnpm_completer/cmd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var initCmd = &cobra.Command{
Use: "init",
Short: "Create a package.json file",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(initCmd).Standalone()

initCmd.Flags().BoolP("help", "h", false, "Output usage information")
initCmd.Flags().String("name", "", "Set the name field in package.json")
initCmd.Flags().String("version", "", "Set the version field in package.json")
initCmd.Flags().String("description", "", "Set the description field in package.json")
initCmd.Flags().String("author", "", "Set the author field in package.json")
initCmd.Flags().String("license", "", "Set the license field in package.json")
initCmd.Flags().String("homepage", "", "Set the homepage field in package.json")
initCmd.Flags().String("repository", "", "Set the repository field in package.json")
initCmd.Flags().String("keywords", "", "Set the keywords field in package.json")

rootCmd.AddCommand(initCmd)
}
5 changes: 4 additions & 1 deletion completers/common/pnpm_completer/cmd/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func init() {
})

carapace.Gen(rebuildCmd).PositionalAnyCompletion(
pnpm.ActionDependencies(),
carapace.Batch(
pnpm.ActionDependencies(),
pnpm.ActionWorkspaceDependencies(),
).ToA(),
)
}
5 changes: 4 additions & 1 deletion completers/common/pnpm_completer/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func init() {
})

carapace.Gen(removeCmd).PositionalAnyCompletion(
pnpm.ActionDependencies(),
carapace.Batch(
pnpm.ActionDependencies(),
pnpm.ActionWorkspaceDependencies(),
).ToA(),
)
}
26 changes: 26 additions & 0 deletions completers/common/pnpm_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/pnpm"
"github.com/spf13/cobra"
)

Expand All @@ -15,6 +16,7 @@ var rootCmd = &cobra.Command{
func Execute() error {
return rootCmd.Execute()
}

func init() {
carapace.Gen(rootCmd).Standalone()

Expand All @@ -23,9 +25,33 @@ func init() {
&cobra.Group{ID: "review", Title: "Review Commands"},
&cobra.Group{ID: "run", Title: "Run Commands"},
&cobra.Group{ID: "store", Title: "Store Commands"},
&cobra.Group{ID: "other", Title: "Other Commands"},
)

rootCmd.Flags().BoolP("help", "h", false, "show help")
rootCmd.Flags().BoolP("recursive", "r", false, "Run the command for each project in the workspace")
rootCmd.Flags().BoolP("version", "v", false, "show version")
rootCmd.Flags().String("filter", "", "set filter")
rootCmd.Flags().String("filter-prod", "", "Restricts the scope to package names matching the given pattern")
rootCmd.Flags().String("loglevel", "", "What level of logs to report")
rootCmd.Flags().Bool("color", false, "Controls colors in the output")
rootCmd.Flags().Bool("no-color", false, "Controls colors in the output")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"filter": pnpm.ActionFilter(),
"filter-prod": pnpm.ActionFilter(),
"loglevel": pnpm.ActionLoglevel(),
})
}

func addWorkspaceFlags(cmd *cobra.Command) {
cmd.Flags().StringArrayP("workspace", "w", []string{""}, "Enable running a command in the context of the given workspace")
cmd.Flags().Bool("workspaces", false, "Enable running a command in the context of all workspaces")

carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
"workspace": carapace.Batch(
pnpm.ActionWorkspaces(),
pnpm.ActionWorkspaceDependencies(),
).ToA(),
})
}
11 changes: 6 additions & 5 deletions completers/common/pnpm_completer/cmd/root_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"github.com/spf13/cobra"
)

var root_rootCmd = &cobra.Command{
var rootRootCmd = &cobra.Command{
Use: "root",
Short: "Print the effective `node_modules` directory",
Short: "Print the effective modules directory",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(root_rootCmd).Standalone()
carapace.Gen(rootRootCmd).Standalone()

root_rootCmd.Flags().BoolP("global", "g", false, "Print the global `node_modules` directory")
rootCmd.AddCommand(root_rootCmd)
rootRootCmd.Flags().BoolP("help", "h", false, "Output usage information")

rootCmd.AddCommand(rootRootCmd)
}
7 changes: 6 additions & 1 deletion completers/common/pnpm_completer/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ func init() {
"loglevel": pnpm.ActionLoglevel(),
})

// TODO complete scripts
carapace.Gen(runCmd).PositionalCompletion(
carapace.Batch(
pnpm.ActionScripts(),
pnpm.ActionWorkspaceScripts(),
).ToA(),
)
}
36 changes: 31 additions & 5 deletions completers/common/pnpm_completer/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,46 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/pnpm"
"github.com/spf13/cobra"
)

var startCmd = &cobra.Command{
Use: "start",
Short: "Runs an arbitrary command specified in the package's \"start\" property",
GroupID: "run",
Run: func(cmd *cobra.Command, args []string) {},
Use: "start",
Short: "Runs an arbitrary command specified in the package's start property of its scripts object",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(startCmd).Standalone()

startCmd.Flags().Bool("aggregate-output", false, "Aggregate output from child processes that are run in parallel")
startCmd.Flags().String("changed-files-ignore-pattern", "", "Defines files to ignore when filtering for changed projects")
startCmd.Flags().Bool("color", false, "Controls colors in the output")
startCmd.Flags().StringP("dir", "C", "", "Change to directory <dir>")
startCmd.Flags().String("filter", "", "set filter")
startCmd.Flags().String("filter-prod", "", "Restricts the scope to package names matching the given pattern")
startCmd.Flags().BoolP("help", "h", false, "Output usage information")
startCmd.Flags().Bool("if-present", false, "Avoid exiting with a non-zero exit code when the script is undefined")
startCmd.Flags().String("loglevel", "", "What level of logs to report")
startCmd.Flags().Bool("no-bail", false, "The command will exit with a 0 exit code even if the script fails")
startCmd.Flags().Bool("no-color", false, "Controls colors in the output")
startCmd.Flags().Bool("parallel", false, "Completely disregard concurrency and topological sorting")
startCmd.Flags().BoolP("recursive", "r", false, "Run the defined package script in every package found in subdirectories")
startCmd.Flags().Bool("report-summary", false, "Save the execution results of every package to \"pnpm-exec-summary.json\"")
startCmd.Flags().Bool("resume-from", false, "Command executed from given package")
startCmd.Flags().Bool("sequential", false, "Run the specified scripts one by one")
startCmd.Flags().Bool("stream", false, "Stream output from child processes immediately")
startCmd.Flags().String("test-pattern", "", "Defines files related to tests.")
startCmd.Flags().Bool("use-stderr", false, "Divert all output to stderr")
startCmd.Flags().Bool("workspace-root", false, "Run the command on the root workspace project")
addWorkspaceFlags(startCmd)
rootCmd.AddCommand(startCmd)

// TODO positional completion
carapace.Gen(startCmd).FlagCompletion(carapace.ActionMap{
"dir": carapace.ActionDirectories(),
"filter": pnpm.ActionFilter(),
"filter-prod": pnpm.ActionFilter(),
"loglevel": pnpm.ActionLoglevel(),
})
}
5 changes: 4 additions & 1 deletion completers/common/pnpm_completer/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func init() {
})

carapace.Gen(updateCmd).PositionalAnyCompletion(
pnpm.ActionDependencyNames(),
carapace.Batch(
pnpm.ActionDependencyNames(),
pnpm.ActionWorkspaceDependencies(),
).ToA(),
)
}
39 changes: 39 additions & 0 deletions pkg/actions/tools/pnpm/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package pnpm

import (
"encoding/json"

"github.com/carapace-sh/carapace"
)

// ActionLocalConfigKeys completes local config keys
func ActionLocalConfigKeys() carapace.Action {
return actionConfigKeys(false)
}

// ActionGlobalConfigKeys completes global config keys
func ActionGlobalConfigKeys() carapace.Action {
return actionConfigKeys(true)
}

func actionConfigKeys(global bool) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
args := []string{"config", "list", "--json"}
if global {
args = append(args, "--global")
}

return carapace.ActionExecCommand("pnpm", args...)(func(output []byte) carapace.Action {
var config map[string]interface{}
if err := json.Unmarshal(output, &config); err != nil {
return carapace.ActionMessage(err.Error())
}

vals := make([]string, 0, len(config))
for key := range config {
vals = append(vals, key)
}
return carapace.ActionValues(vals...)
})
}).Tag("config keys")
}
Loading