Skip to content

Commit

Permalink
Merge pull request #2350 from aftix/update_nix
Browse files Browse the repository at this point in the history
Updated nix completer with the new flake APIs
  • Loading branch information
rsteube authored Apr 17, 2024
2 parents f7de9d9 + 199e396 commit 49418e2
Show file tree
Hide file tree
Showing 48 changed files with 637 additions and 105 deletions.
4 changes: 4 additions & 0 deletions completers/nix_completer/cmd/build.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/nix"
"github.com/spf13/cobra"
)

Expand All @@ -15,12 +16,14 @@ var buildCmd = &cobra.Command{
func init() {
carapace.Gen(buildCmd).Standalone()

buildCmd.Flags().Bool("dry-run", false, "Show what this command would do without doing it")
buildCmd.Flags().Bool("json", false, "Produce output in JSON format, suitable for consumption by another program.")
buildCmd.Flags().Bool("no-link", false, "Do not create symlinks to the build results.")
buildCmd.Flags().StringP("out-link", "o", "", "Use path as prefix for the symlinks to the build results.")
buildCmd.Flags().Bool("print-out-paths", false, "Print the resulting output paths")
buildCmd.Flags().String("profile", "", "The profile to update.")
buildCmd.Flags().Bool("rebuild", false, "Rebuild an already built package and compare the result to the existing store paths.")
buildCmd.Flags().Bool("stdin", false, "Read installables from the standard input")

addEvaluationFlags(buildCmd)
addFlakeFlags(buildCmd)
Expand All @@ -33,4 +36,5 @@ func init() {
"out-link": carapace.ActionFiles(),
"profile": carapace.ActionFiles(),
})
carapace.Gen(buildCmd).PositionalCompletion(nix.ActionFlakes())
}
8 changes: 6 additions & 2 deletions completers/nix_completer/cmd/bundle.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/nix"
"github.com/spf13/cobra"
)

Expand All @@ -19,9 +20,12 @@ func init() {
bundleCmd.Flags().StringP("out-link", "o", "", "Override the name of the symlink to the build result")
rootCmd.AddCommand(bundleCmd)

// TODO flag completion

addEvaluationFlags(bundleCmd)
addFlakeFlags(bundleCmd)
addLoggingFlags(bundleCmd)

carapace.Gen(bundleCmd).FlagCompletion(carapace.ActionMap{
"bundler": nix.ActionFlakes(),
})
carapace.Gen(bundleCmd).PositionalCompletion(nix.ActionInstallables())
}
4 changes: 3 additions & 1 deletion completers/nix_completer/cmd/copy.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/nix"
"github.com/spf13/cobra"
)

Expand All @@ -17,6 +18,7 @@ func init() {

copyCmd.Flags().String("from", "", "URL of the source Nix store")
copyCmd.Flags().Bool("no-check-sigs", false, "Do not require that paths are signed by trusted keys")
copyCmd.Flags().Bool("stdin", false, "Read installables from the standard input")
copyCmd.Flags().BoolP("substitute-on-destination", "s", false, "Whether to try substitutes on the destination store")
copyCmd.Flags().String("to", "", "URL of the destination Nix store")
rootCmd.AddCommand(copyCmd)
Expand All @@ -27,5 +29,5 @@ func init() {

// TODO flag completion

// TODO positional completion
carapace.Gen(copyCmd).PositionalAnyCompletion(nix.ActionInstallables())
}
10 changes: 10 additions & 0 deletions completers/nix_completer/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,15 @@ var daemonCmd = &cobra.Command{
func init() {
carapace.Gen(daemonCmd).Standalone()

daemonCmd.Flags().Bool("default-trust", false, "Use Nix's default trust")
daemonCmd.Flags().Bool("force-trusted", false, "Force the daemon to trust connecting clients")
daemonCmd.Flags().Bool("force-untrusted", false, "Force the daemon to not trust connecting clients")
daemonCmd.Flags().Bool("stdio", false, "Attach to standard I/O instead of trying to bind to a Unix socket")

daemonCmd.MarkFlagsMutuallyExclusive("default-trust", "force-trusted", "force-untrusted")

addEvaluationFlags(daemonCmd)
addLoggingFlags(daemonCmd)

rootCmd.AddCommand(daemonCmd)
}
23 changes: 23 additions & 0 deletions completers/nix_completer/cmd/derivation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

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

var derivationCmd = &cobra.Command{
Use: "derivation",
Short: "work with derivations",
GroupID: "utility",
Run: func(cmd *cobra.Command, args []string) {},
}

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

rootCmd.AddCommand(derivationCmd)

addEvaluationFlags(derivationCmd)
addFlakeFlags(derivationCmd)
addLoggingFlags(derivationCmd)
}
22 changes: 22 additions & 0 deletions completers/nix_completer/cmd/derivation_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

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

var derivation_addCmd = &cobra.Command{
Use: "add",
Short: "add a store derivation",
Run: func(cmd *cobra.Command, args []string) {},
}

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

derivation_addCmd.Flags().Bool("dry-run", false, "Show what this command would do without doing it")

derivationCmd.AddCommand(derivation_addCmd)

addLoggingFlags(derivation_addCmd)
}
28 changes: 28 additions & 0 deletions completers/nix_completer/cmd/derivation_show.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/carapace-sh/carapace-bin/pkg/actions/tools/nix"
"github.com/spf13/cobra"
)

var derivation_showCmd = &cobra.Command{
Use: "show",
Short: "work with derivations",
Run: func(cmd *cobra.Command, args []string) {},
}

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

derivation_showCmd.Flags().Bool("dry-run", false, "Show what this command would do without doing it")
derivation_showCmd.Flags().Bool("stdin", false, "Read installables from the standard input")

derivationCmd.AddCommand(derivation_showCmd)

addEvaluationFlags(derivation_showCmd)
addFlakeFlags(derivation_showCmd)
addLoggingFlags(derivation_showCmd)

carapace.Gen(derivation_showCmd).PositionalAnyCompletion(nix.ActionInstallables())
}
22 changes: 0 additions & 22 deletions completers/nix_completer/cmd/describeStores.go

This file was deleted.

2 changes: 2 additions & 0 deletions completers/nix_completer/cmd/develop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/os"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/nix"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -45,4 +46,5 @@ func init() {
"keep": os.ActionEnvironmentVariables(),
"unset": os.ActionEnvironmentVariables(),
})
carapace.Gen(developCmd).PositionalCompletion(nix.ActionDevShells())
}
3 changes: 2 additions & 1 deletion completers/nix_completer/cmd/edit.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/nix"
"github.com/spf13/cobra"
)

Expand All @@ -21,5 +22,5 @@ func init() {
addFlakeFlags(editCmd)
addLoggingFlags(editCmd)

// TODO positional completion
carapace.Gen(editCmd).PositionalAnyCompletion(nix.ActionInstallables())
}
3 changes: 2 additions & 1 deletion completers/nix_completer/cmd/eval.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/nix"
"github.com/spf13/cobra"
)

Expand All @@ -28,5 +29,5 @@ func init() {

// TODO flag completion

// TODO positional completion
carapace.Gen(evalCmd).PositionalAnyCompletion(nix.ActionInstallables())
}
28 changes: 28 additions & 0 deletions completers/nix_completer/cmd/flake_check.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/carapace-sh/carapace-bin/pkg/actions/tools/nix"
"github.com/spf13/cobra"
)

var flake_checkCmd = &cobra.Command{
Use: "check [flags] [flake-url]",
Short: "check whether the flake evaluates and runs its tests",
Run: func(cmd *cobra.Command, args []string) {},
}

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

flake_checkCmd.Flags().Bool("all-systems", false, "Check the outputs for all systems")
flake_checkCmd.Flags().Bool("no-build", false, "Do not build checks")

addEvaluationFlags(flake_checkCmd)
addFlakeFlags(flake_checkCmd)
addLoggingFlags(flake_checkCmd)

carapace.Gen(flake_checkCmd).PositionalCompletion(nix.ActionFlakes())

flakeCmd.AddCommand(flake_checkCmd)
}
30 changes: 30 additions & 0 deletions completers/nix_completer/cmd/flake_clone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

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

var flake_cloneCmd = &cobra.Command{
Use: "clone [flags] [flake-url]",
Short: "clone flake repository",
Run: func(cmd *cobra.Command, args []string) {},
}

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

flake_cloneCmd.Flags().StringP("dest", "f", "", "Specify target directory for flake repository")

addEvaluationFlags(flake_cloneCmd)
addFlakeFlags(flake_cloneCmd)
addLoggingFlags(flake_cloneCmd)

carapace.Gen(flake_cloneCmd).FlagCompletion(carapace.ActionMap{
"dest": carapace.ActionDirectories(),
})
carapace.Gen(flake_cloneCmd).PositionalCompletion(nix.ActionFlakes())

flakeCmd.AddCommand(flake_cloneCmd)
}
29 changes: 29 additions & 0 deletions completers/nix_completer/cmd/flake_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

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

var flake_initCmd = &cobra.Command{
Use: "init",
Short: "create a flake in current directory from a template",
Run: func(cmd *cobra.Command, args []string) {},
}

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

flake_initCmd.Flags().StringP("template", "t", "default", "The template to use")

addEvaluationFlags(flake_initCmd)
addFlakeFlags(flake_initCmd)
addLoggingFlags(flake_initCmd)

carapace.Gen(flake_initCmd).FlagCompletion(carapace.ActionMap{
"template": nix.ActionTemplates(),
})

flakeCmd.AddCommand(flake_initCmd)
}
25 changes: 25 additions & 0 deletions completers/nix_completer/cmd/flake_lock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

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

var flake_lockCmd = &cobra.Command{
Use: "lock [flags] [flake-url]",
Short: "create missing lockfile entries",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addEvaluationFlags(flake_lockCmd)
addFlakeFlags(flake_lockCmd)
addLoggingFlags(flake_lockCmd)

carapace.Gen(flake_lockCmd).PositionalCompletion(nix.ActionFlakes())

flakeCmd.AddCommand(flake_lockCmd)
}
28 changes: 28 additions & 0 deletions completers/nix_completer/cmd/flake_metadata.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/carapace-sh/carapace-bin/pkg/actions/tools/nix"
"github.com/spf13/cobra"
)

var flake_metadataCmd = &cobra.Command{
Use: "metadata [flags] [flake-url]",
Short: "show flake metadata",
Run: func(cmd *cobra.Command, args []string) {},
Aliases: []string{"info"},
}

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

flake_metadataCmd.Flags().Bool("json", false, "Produce output in JSON format")

addEvaluationFlags(flake_metadataCmd)
addFlakeFlags(flake_metadataCmd)
addLoggingFlags(flake_metadataCmd)

carapace.Gen(flake_metadataCmd).PositionalCompletion(nix.ActionFlakes())

flakeCmd.AddCommand(flake_metadataCmd)
}
Loading

0 comments on commit 49418e2

Please sign in to comment.