Skip to content

Commit

Permalink
- Added completer for nixos-rebuild
Browse files Browse the repository at this point in the history
- Fixed nix completer `builders` and `substituters` flags not being StringArray
  • Loading branch information
aftix committed Apr 20, 2024
1 parent 49418e2 commit 77ab979
Show file tree
Hide file tree
Showing 13 changed files with 522 additions and 2 deletions.
45 changes: 43 additions & 2 deletions completers/nix_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
rootCmd.Flags().String("build-hook", "", "Set the build-hook setting")
rootCmd.Flags().String("build-poll-interval", "", "Set the build-poll-interval setting")
rootCmd.Flags().String("build-users-group", "", "Set the build-users-group setting")
rootCmd.Flags().String("builders", "", "Set the builders setting")
rootCmd.Flags().StringArray("builders", nil, "Set the builders setting")
rootCmd.Flags().Bool("builders-use-substitutes", false, "Enable the builders-use-substitutes setting")
rootCmd.Flags().String("commit-lockfile-summary", "", "Set the commit-lockfile-summary setting")
rootCmd.Flags().Bool("compress-build-log", false, "Enable the compress-build-log setting")
Expand Down Expand Up @@ -167,7 +167,7 @@ func init() {
rootCmd.Flags().String("stalled-download-timeout", "", "Set the stalled-download-timeout setting")
rootCmd.Flags().String("store", "", "Set the store setting")
rootCmd.Flags().Bool("substitute", false, "Enable the substitute setting")
rootCmd.Flags().String("substituters", "", "Set the substituters setting")
rootCmd.Flags().StringArray("substituters", nil, "Set the substituters setting")
rootCmd.Flags().Bool("sync-before-registering", false, "Enable the sync-before-registering setting")
rootCmd.Flags().String("system", "", "Set the system setting")
rootCmd.Flags().String("system-features", "", "Set the system-features setting")
Expand All @@ -193,6 +193,47 @@ func init() {

rootCmd.Flag("option").Nargs = 2

rootCmd.MarkFlagsMutuallyExclusive("accept-flake-config", "no-accept-flake-config")
rootCmd.MarkFlagsMutuallyExclusive("allow-dirty", "no-allow-dirty")
rootCmd.MarkFlagsMutuallyExclusive("allow-import-from-derivation", "no-allow-import-from-derivation")
rootCmd.MarkFlagsMutuallyExclusive("allow-new-privileges", "no-allow-new-privileges")
rootCmd.MarkFlagsMutuallyExclusive("allow-symlinked-store", "no-allow-symlinked-store")
rootCmd.MarkFlagsMutuallyExclusive("allow-unsafe-native-code-during-evaluation", "no-allow-unsafe-native-code-during-evaluation")
rootCmd.MarkFlagsMutuallyExclusive("auto-optimise-store", "no-auto-optimise-store")
rootCmd.MarkFlagsMutuallyExclusive("builders-use-substitutes", "no-builders-use-substitutes")
rootCmd.MarkFlagsMutuallyExclusive("compress-build-log", "no-compress-build-log")
rootCmd.MarkFlagsMutuallyExclusive("enforce-determinism", "no-enforce-determinism")
rootCmd.MarkFlagsMutuallyExclusive("eval-cache", "no-eval-cache")
rootCmd.MarkFlagsMutuallyExclusive("fallback", "no-fallback")
rootCmd.MarkFlagsMutuallyExclusive("filter-syscalls", "no-filter-syscalls")
rootCmd.MarkFlagsMutuallyExclusive("fsync-metadata", "no-fsync-metadata")
rootCmd.MarkFlagsMutuallyExclusive("http2", "no-http2")
rootCmd.MarkFlagsMutuallyExclusive("ignore-try", "no-ignore-try")
rootCmd.MarkFlagsMutuallyExclusive("impersonate-linux-26", "no-impersonate-linux-26")
rootCmd.MarkFlagsMutuallyExclusive("keep-build-log", "no-keep-build-log")
rootCmd.MarkFlagsMutuallyExclusive("keep-derivations", "no-keep-derivations")
rootCmd.MarkFlagsMutuallyExclusive("keep-env-derivations", "no-keep-env-derivations")
rootCmd.MarkFlagsMutuallyExclusive("keep-failed", "no-keep-failed")
rootCmd.MarkFlagsMutuallyExclusive("keep-going", "no-keep-going")
rootCmd.MarkFlagsMutuallyExclusive("keep-outputs", "no-keep-outputs")
rootCmd.MarkFlagsMutuallyExclusive("preallocate-contents", "no-preallocate-contents")
rootCmd.MarkFlagsMutuallyExclusive("print-missing", "no-print-missing")
rootCmd.MarkFlagsMutuallyExclusive("pure-eval", "no-pure-eval")
rootCmd.MarkFlagsMutuallyExclusive("require-sigs", "no-require-sigs")
rootCmd.MarkFlagsMutuallyExclusive("restrict-eval", "no-restrict-eval")
rootCmd.MarkFlagsMutuallyExclusive("run-diff-hook", "no-run-diff-hook")
rootCmd.MarkFlagsMutuallyExclusive("sandbox", "no-sandbox")
rootCmd.MarkFlagsMutuallyExclusive("sandbox-fallback", "no-sandbox-fallback")
rootCmd.MarkFlagsMutuallyExclusive("show-trace", "no-show-trace")
rootCmd.MarkFlagsMutuallyExclusive("substitute", "no-substitute")
rootCmd.MarkFlagsMutuallyExclusive("sync-before-registering", "no-sync-before-registering")
rootCmd.MarkFlagsMutuallyExclusive("trace-function-calls", "no-trace-function-calls")
rootCmd.MarkFlagsMutuallyExclusive("trace-verbose", "no-trace-verbose")
rootCmd.MarkFlagsMutuallyExclusive("use-case-hack", "no-use-case-hack")
rootCmd.MarkFlagsMutuallyExclusive("use-registries", "no-use-registries")
rootCmd.MarkFlagsMutuallyExclusive("use-sqlite-wal", "no-use-sqlite-wal")
rootCmd.MarkFlagsMutuallyExclusive("warn-dirty", "no-warn-dirty")

// TODO find out how flags shall be completed (nix doc insufficient)
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"log-format": carapace.ActionValues("raw", "internal-json", "bar", "bar-with-logs"),
Expand Down
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/boot.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 bootCmd = &cobra.Command{
Use: "boot",
Short: "Build the new configuration and make it the boot default, but do not activate it",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(bootCmd)

rootCmd.AddCommand(bootCmd)
}
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/build.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 buildCmd = &cobra.Command{
Use: "build",
Short: "build the new configuration without activating it or adding it to the boot menu",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(buildCmd)

rootCmd.AddCommand(buildCmd)
}
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/build_vm.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 build_vmCmd = &cobra.Command{
Use: "build-vm",
Short: "Build a script that starts a NixOS virtual machine with the configuration",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(build_vmCmd)

rootCmd.AddCommand(build_vmCmd)
}
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/build_vm_with_bootloader.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 build_vm_with_bootloaderCmd = &cobra.Command{
Use: "build-vm-with-bootloader",
Short: "Like build-vm, but boots with the regular bootloader of your configuration",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(build_vm_with_bootloaderCmd)

rootCmd.AddCommand(build_vm_with_bootloaderCmd)
}
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/dry_activate.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 dry_activateCmd = &cobra.Command{
Use: "dry-activate",
Short: "Build the new configuration, but show what changes would occur on activation instead of activating the configuration",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(dry_activateCmd)

rootCmd.AddCommand(dry_activateCmd)
}
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/dry_build.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 dry_buildCmd = &cobra.Command{
Use: "dry-build",
Short: "Show what store paths would be built or downloaded, but otherwise do nothing",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(dry_buildCmd)

rootCmd.AddCommand(dry_buildCmd)
}
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/edit.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 editCmd = &cobra.Command{
Use: "edit",
Short: "Opens configuration.nix in the default editor",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(editCmd)

rootCmd.AddCommand(editCmd)
}
22 changes: 22 additions & 0 deletions completers/nixos-rebuild_completer/cmd/list_generations.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 list_generationsCmd = &cobra.Command{
Use: "list-generations",
Short: "List the available generations",
Run: func(cmd *cobra.Command, args []string) {},
}

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

list_generationsCmd.Flags().Bool("json", false, "Output in JSON")

addFlags(list_generationsCmd)

rootCmd.AddCommand(list_generationsCmd)
}
20 changes: 20 additions & 0 deletions completers/nixos-rebuild_completer/cmd/repl.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 replCmd = &cobra.Command{
Use: "repl",
Short: "Open the configuration in `nix repl`",
Run: func(cmd *cobra.Command, args []string) {},
}

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

addFlags(replCmd)

rootCmd.AddCommand(replCmd)
}
Loading

0 comments on commit 77ab979

Please sign in to comment.