diff --git a/completers/nix_completer/cmd/build.go b/completers/nix_completer/cmd/build.go index b245ddb585..c8d060046d 100644 --- a/completers/nix_completer/cmd/build.go +++ b/completers/nix_completer/cmd/build.go @@ -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" ) @@ -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) @@ -33,4 +36,5 @@ func init() { "out-link": carapace.ActionFiles(), "profile": carapace.ActionFiles(), }) + carapace.Gen(buildCmd).PositionalCompletion(nix.ActionFlakes()) } diff --git a/completers/nix_completer/cmd/bundle.go b/completers/nix_completer/cmd/bundle.go index 468f06e51d..59fc72befd 100644 --- a/completers/nix_completer/cmd/bundle.go +++ b/completers/nix_completer/cmd/bundle.go @@ -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" ) @@ -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()) } diff --git a/completers/nix_completer/cmd/copy.go b/completers/nix_completer/cmd/copy.go index 582d0086a0..939aa6448a 100644 --- a/completers/nix_completer/cmd/copy.go +++ b/completers/nix_completer/cmd/copy.go @@ -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" ) @@ -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) @@ -27,5 +29,5 @@ func init() { // TODO flag completion - // TODO positional completion + carapace.Gen(copyCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/daemon.go b/completers/nix_completer/cmd/daemon.go index 2d11cefea0..9ddbf51555 100644 --- a/completers/nix_completer/cmd/daemon.go +++ b/completers/nix_completer/cmd/daemon.go @@ -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) } diff --git a/completers/nix_completer/cmd/derivation.go b/completers/nix_completer/cmd/derivation.go new file mode 100644 index 0000000000..136663cda2 --- /dev/null +++ b/completers/nix_completer/cmd/derivation.go @@ -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) +} diff --git a/completers/nix_completer/cmd/derivation_add.go b/completers/nix_completer/cmd/derivation_add.go new file mode 100644 index 0000000000..b97916b603 --- /dev/null +++ b/completers/nix_completer/cmd/derivation_add.go @@ -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) +} diff --git a/completers/nix_completer/cmd/derivation_show.go b/completers/nix_completer/cmd/derivation_show.go new file mode 100644 index 0000000000..37e53affa5 --- /dev/null +++ b/completers/nix_completer/cmd/derivation_show.go @@ -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()) +} diff --git a/completers/nix_completer/cmd/describeStores.go b/completers/nix_completer/cmd/describeStores.go deleted file mode 100644 index d19537cf09..0000000000 --- a/completers/nix_completer/cmd/describeStores.go +++ /dev/null @@ -1,22 +0,0 @@ -package cmd - -import ( - "github.com/carapace-sh/carapace" - "github.com/spf13/cobra" -) - -var describeStoresCmd = &cobra.Command{ - Use: "describe-stores", - Short: "show registered store types and their available options", - GroupID: "utility", - Run: func(cmd *cobra.Command, args []string) {}, -} - -func init() { - carapace.Gen(describeStoresCmd).Standalone() - - describeStoresCmd.Flags().Bool("json", false, "Produce output in JSON format") - rootCmd.AddCommand(describeStoresCmd) - - // TODO positional completion -} diff --git a/completers/nix_completer/cmd/develop.go b/completers/nix_completer/cmd/develop.go index 1cba7fa928..0b40a2675f 100644 --- a/completers/nix_completer/cmd/develop.go +++ b/completers/nix_completer/cmd/develop.go @@ -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" ) @@ -45,4 +46,5 @@ func init() { "keep": os.ActionEnvironmentVariables(), "unset": os.ActionEnvironmentVariables(), }) + carapace.Gen(developCmd).PositionalCompletion(nix.ActionDevShells()) } diff --git a/completers/nix_completer/cmd/edit.go b/completers/nix_completer/cmd/edit.go index 7d4c666672..3ca6ebb23f 100644 --- a/completers/nix_completer/cmd/edit.go +++ b/completers/nix_completer/cmd/edit.go @@ -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" ) @@ -21,5 +22,5 @@ func init() { addFlakeFlags(editCmd) addLoggingFlags(editCmd) - // TODO positional completion + carapace.Gen(editCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/eval.go b/completers/nix_completer/cmd/eval.go index 7f10beb9ab..0a59dc359e 100644 --- a/completers/nix_completer/cmd/eval.go +++ b/completers/nix_completer/cmd/eval.go @@ -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" ) @@ -28,5 +29,5 @@ func init() { // TODO flag completion - // TODO positional completion + carapace.Gen(evalCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/flake_check.go b/completers/nix_completer/cmd/flake_check.go new file mode 100644 index 0000000000..f1013edb9a --- /dev/null +++ b/completers/nix_completer/cmd/flake_check.go @@ -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) +} diff --git a/completers/nix_completer/cmd/flake_clone.go b/completers/nix_completer/cmd/flake_clone.go new file mode 100644 index 0000000000..bb63318ace --- /dev/null +++ b/completers/nix_completer/cmd/flake_clone.go @@ -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) +} diff --git a/completers/nix_completer/cmd/flake_init.go b/completers/nix_completer/cmd/flake_init.go new file mode 100644 index 0000000000..0042f55fa1 --- /dev/null +++ b/completers/nix_completer/cmd/flake_init.go @@ -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) +} diff --git a/completers/nix_completer/cmd/flake_lock.go b/completers/nix_completer/cmd/flake_lock.go new file mode 100644 index 0000000000..f9b4549072 --- /dev/null +++ b/completers/nix_completer/cmd/flake_lock.go @@ -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) +} diff --git a/completers/nix_completer/cmd/flake_metadata.go b/completers/nix_completer/cmd/flake_metadata.go new file mode 100644 index 0000000000..14762867cd --- /dev/null +++ b/completers/nix_completer/cmd/flake_metadata.go @@ -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) +} diff --git a/completers/nix_completer/cmd/flake_new.go b/completers/nix_completer/cmd/flake_new.go new file mode 100644 index 0000000000..8cf8f6e71b --- /dev/null +++ b/completers/nix_completer/cmd/flake_new.go @@ -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_newCmd = &cobra.Command{ + Use: "new [flags] DIR", + Short: "create a flake in target directory from a template", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(flake_newCmd).Standalone() + + flake_newCmd.Flags().StringP("template", "t", "default", "The template to use") + + addEvaluationFlags(flake_newCmd) + addFlakeFlags(flake_newCmd) + addLoggingFlags(flake_newCmd) + + carapace.Gen(flake_newCmd).FlagCompletion(carapace.ActionMap{ + "template": nix.ActionTemplates(), + }) + carapace.Gen(flake_newCmd).PositionalCompletion(carapace.ActionDirectories()) + + flakeCmd.AddCommand(flake_newCmd) +} diff --git a/completers/nix_completer/cmd/flake_prefetch.go b/completers/nix_completer/cmd/flake_prefetch.go new file mode 100644 index 0000000000..3bb8b0dd48 --- /dev/null +++ b/completers/nix_completer/cmd/flake_prefetch.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace-bin/pkg/actions/tools/nix" + "github.com/spf13/cobra" +) + +var flake_prefetchCmd = &cobra.Command{ + Use: "prefetch [flags] [flake-url]", + Short: "download the source tree denoted by a flake reference into the nix store", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(flake_prefetchCmd).Standalone() + + flake_prefetchCmd.Flags().Bool("json", false, "Produce output in JSON format") + + addEvaluationFlags(flake_prefetchCmd) + addFlakeFlags(flake_prefetchCmd) + addLoggingFlags(flake_prefetchCmd) + + carapace.Gen(flake_prefetchCmd).PositionalCompletion(nix.ActionFlakes()) + + flakeCmd.AddCommand(flake_prefetchCmd) +} diff --git a/completers/nix_completer/cmd/flake_show.go b/completers/nix_completer/cmd/flake_show.go new file mode 100644 index 0000000000..07d32992fa --- /dev/null +++ b/completers/nix_completer/cmd/flake_show.go @@ -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_showCmd = &cobra.Command{ + Use: "show [flags] [flake-url]", + Short: "show the outputs provided by a flake", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(flake_showCmd).Standalone() + + flake_showCmd.Flags().Bool("all-systems", false, "Show the contents of outputs for all systems") + flake_showCmd.Flags().Bool("json", false, "Produce output in JSON format") + flake_showCmd.Flags().Bool("legacy", false, "Show the contents of the legacyPackages output") + + addEvaluationFlags(flake_showCmd) + addFlakeFlags(flake_showCmd) + addLoggingFlags(flake_showCmd) + + carapace.Gen(flake_showCmd).PositionalCompletion(nix.ActionFlakes()) + + flakeCmd.AddCommand(flake_showCmd) +} diff --git a/completers/nix_completer/cmd/flake_update.go b/completers/nix_completer/cmd/flake_update.go new file mode 100644 index 0000000000..5f234b8222 --- /dev/null +++ b/completers/nix_completer/cmd/flake_update.go @@ -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_updateCmd = &cobra.Command{ + Use: "update [flags] [flake-url]", + Short: "update flake lock file", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(flake_updateCmd).Standalone() + + addEvaluationFlags(flake_updateCmd) + addFlakeFlags(flake_updateCmd) + addLoggingFlags(flake_updateCmd) + + carapace.Gen(flake_updateCmd).PositionalCompletion(nix.ActionFlakes()) + + flakeCmd.AddCommand(flake_updateCmd) +} diff --git a/completers/nix_completer/cmd/help.go b/completers/nix_completer/cmd/help.go index 57fa434c26..58d7d26c10 100644 --- a/completers/nix_completer/cmd/help.go +++ b/completers/nix_completer/cmd/help.go @@ -17,5 +17,7 @@ func init() { rootCmd.AddCommand(helpCmd) - // TODO positional completion + carapace.Gen(helpCmd).PositionalAnyCompletion( + carapace.ActionCommands(rootCmd), + ) } diff --git a/completers/nix_completer/cmd/helpStores.go b/completers/nix_completer/cmd/helpStores.go new file mode 100644 index 0000000000..59daa9ddb3 --- /dev/null +++ b/completers/nix_completer/cmd/helpStores.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var helpStoresCmd = &cobra.Command{ + Use: "help", + Short: "show help about store types and their settings", + GroupID: "main", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(helpStoresCmd).Standalone() + + rootCmd.AddCommand(helpStoresCmd) + + // TODO positional completion +} diff --git a/completers/nix_completer/cmd/log.go b/completers/nix_completer/cmd/log.go index 17eeb6673a..800fcd2fee 100644 --- a/completers/nix_completer/cmd/log.go +++ b/completers/nix_completer/cmd/log.go @@ -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" ) @@ -21,5 +22,5 @@ func init() { addFlakeFlags(logCmd) addLoggingFlags(logCmd) - // TODO positional completion + carapace.Gen(logCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/pathInfo.go b/completers/nix_completer/cmd/pathInfo.go index a2f044c20a..01b811e230 100644 --- a/completers/nix_completer/cmd/pathInfo.go +++ b/completers/nix_completer/cmd/pathInfo.go @@ -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" ) @@ -26,5 +27,5 @@ func init() { addFlakeFlags(pathInfoCmd) addLoggingFlags(pathInfoCmd) - // TODO positional completion + carapace.Gen(pathInfoCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/printDevEnv.go b/completers/nix_completer/cmd/printDevEnv.go index da1100bdd1..887f5d6e1f 100644 --- a/completers/nix_completer/cmd/printDevEnv.go +++ b/completers/nix_completer/cmd/printDevEnv.go @@ -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" ) @@ -17,6 +18,7 @@ func init() { printDevEnvCmd.Flags().Bool("json", false, "Produce output in JSON format") printDevEnvCmd.Flags().String("profile", "", "The profile to operate on") + printDevEnvCmd.Flags().String("redirect", "", "Redirect a store path to a mutable location") rootCmd.AddCommand(printDevEnvCmd) addEvaluationFlags(printDevEnvCmd) @@ -26,6 +28,5 @@ func init() { carapace.Gen(printDevEnvCmd).FlagCompletion(carapace.ActionMap{ "profile": carapace.ActionFiles(), }) - - // TODO positional completion + carapace.Gen(printDevEnvCmd).PositionalCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/profile_install.go b/completers/nix_completer/cmd/profile_install.go index abd81ae789..08edb66e6b 100644 --- a/completers/nix_completer/cmd/profile_install.go +++ b/completers/nix_completer/cmd/profile_install.go @@ -1,8 +1,6 @@ package cmd import ( - "strings" - "github.com/carapace-sh/carapace" "github.com/carapace-sh/carapace-bin/pkg/actions/tools/nix" "github.com/spf13/cobra" @@ -19,6 +17,7 @@ func init() { profile_installCmd.Flags().String("priority", "", "The priority of the package to install") profile_installCmd.Flags().String("profile", "", "The profile to operate on") + profile_installCmd.Flags().Bool("stdin", false, "Read installables from the standard input") profileCmd.AddCommand(profile_installCmd) addEvaluationFlags(profile_installCmd) @@ -29,27 +28,5 @@ func init() { "profile": carapace.ActionDirectories(), }) - carapace.Gen(profile_installCmd).PositionalAnyCompletion( - carapace.ActionMultiParts("#", func(c carapace.Context) carapace.Action { - switch len(c.Parts) { - case 0: - return carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action { - switch len(c.Parts) { - case 0: - return nix.ActionLocalChannels().Suffix("#") - case 1: - return carapace.ActionMessage("TODO: support branch completion") // TODO support branch completion - default: - return carapace.ActionValues() - } - }) - - case 1: - return nix.ActionPackages(strings.SplitN(c.Parts[0], "/", 2)[0]) - - default: - return carapace.ActionValues() - } - }), - ) + carapace.Gen(profile_installCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/realisation_info.go b/completers/nix_completer/cmd/realisation_info.go index 7fefb1af95..740981e132 100644 --- a/completers/nix_completer/cmd/realisation_info.go +++ b/completers/nix_completer/cmd/realisation_info.go @@ -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" ) @@ -21,5 +22,5 @@ func init() { addFlakeFlags(realisation_infoCmd) addLoggingFlags(realisation_infoCmd) - // TODO positional completion + carapace.Gen(realisation_infoCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/registry_add.go b/completers/nix_completer/cmd/registry_add.go index 51f476320d..7d566b5965 100644 --- a/completers/nix_completer/cmd/registry_add.go +++ b/completers/nix_completer/cmd/registry_add.go @@ -23,6 +23,5 @@ func init() { carapace.Gen(registry_addCmd).FlagCompletion(carapace.ActionMap{ "registry": carapace.ActionFiles(), }) - // TODO positional completion } diff --git a/completers/nix_completer/cmd/registry_pin.go b/completers/nix_completer/cmd/registry_pin.go index 772498bb28..65add1a3a7 100644 --- a/completers/nix_completer/cmd/registry_pin.go +++ b/completers/nix_completer/cmd/registry_pin.go @@ -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" ) @@ -23,6 +24,5 @@ func init() { carapace.Gen(registry_pinCmd).FlagCompletion(carapace.ActionMap{ "registry": carapace.ActionFiles(), }) - - // TODO positional completion + carapace.Gen(registry_pinCmd).PositionalCompletion(nix.ActionFlakes()) } diff --git a/completers/nix_completer/cmd/registry_remove.go b/completers/nix_completer/cmd/registry_remove.go index 6a6c995715..be7f7adb70 100644 --- a/completers/nix_completer/cmd/registry_remove.go +++ b/completers/nix_completer/cmd/registry_remove.go @@ -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" ) @@ -22,6 +23,5 @@ func init() { carapace.Gen(registry_removeCmd).FlagCompletion(carapace.ActionMap{ "registry": carapace.ActionFiles(), }) - - // TODO positional completion + carapace.Gen(registry_removeCmd).PositionalAnyCompletion(nix.ActionFlakes()) } diff --git a/completers/nix_completer/cmd/repl.go b/completers/nix_completer/cmd/repl.go index 91a20722e2..1c1ee2e445 100644 --- a/completers/nix_completer/cmd/repl.go +++ b/completers/nix_completer/cmd/repl.go @@ -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" ) @@ -17,10 +18,12 @@ func init() { rootCmd.AddCommand(replCmd) + replCmd.Flags().Bool("stdin", false, "Read installables from the standard input") + addEvaluationFlags(replCmd) addFlakeFlags(replCmd) addInterpretationFlags(replCmd) addLoggingFlags(replCmd) - // TODO positional completion + carapace.Gen(replCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/run.go b/completers/nix_completer/cmd/run.go index 0aa27896fe..201789046d 100644 --- a/completers/nix_completer/cmd/run.go +++ b/completers/nix_completer/cmd/run.go @@ -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" ) @@ -21,5 +22,5 @@ func init() { addFlakeFlags(runCmd) addLoggingFlags(runCmd) - // TODO positional completion + carapace.Gen(runCmd).PositionalCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/search.go b/completers/nix_completer/cmd/search.go index 89605fe43c..108ae8a174 100644 --- a/completers/nix_completer/cmd/search.go +++ b/completers/nix_completer/cmd/search.go @@ -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" ) @@ -22,4 +23,6 @@ func init() { addEvaluationFlags(searchCmd) addFlakeFlags(searchCmd) addLoggingFlags(searchCmd) + + carapace.Gen(searchCmd).PositionalCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/shell.go b/completers/nix_completer/cmd/shell.go index 6e0aeb5342..36ba2f4efc 100644 --- a/completers/nix_completer/cmd/shell.go +++ b/completers/nix_completer/cmd/shell.go @@ -2,6 +2,8 @@ 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" ) @@ -18,6 +20,7 @@ func init() { shellCmd.Flags().StringP("command", "c", "", "Command and arguments to be executed, defaulting to $SHELL") shellCmd.Flags().BoolP("ignore-environment", "i", false, "Clear the entire environment") shellCmd.Flags().StringP("keep", "k", "", "Keep the environment variable name") + shellCmd.Flags().Bool("stdin", false, "Read installables from the standard input") shellCmd.Flags().StringP("unset", "u", "", "Unset the environment variable name") rootCmd.AddCommand(shellCmd) @@ -27,7 +30,9 @@ func init() { addFlakeFlags(shellCmd) addLoggingFlags(shellCmd) - // TODO flag completion - - // TODO positional completion + carapace.Gen(shellCmd).FlagCompletion(carapace.ActionMap{ + "keep": os.ActionEnvironmentVariables(), + "unset": os.ActionEnvironmentVariables(), + }) + carapace.Gen(shellCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/showDerivation.go b/completers/nix_completer/cmd/showDerivation.go deleted file mode 100644 index f1eb8300ea..0000000000 --- a/completers/nix_completer/cmd/showDerivation.go +++ /dev/null @@ -1,26 +0,0 @@ -package cmd - -import ( - "github.com/carapace-sh/carapace" - "github.com/spf13/cobra" -) - -var showDerivationCmd = &cobra.Command{ - Use: "show-derivation", - Short: "show the contents of a store derivation", - GroupID: "utility", - Run: func(cmd *cobra.Command, args []string) {}, -} - -func init() { - carapace.Gen(showDerivationCmd).Standalone() - - showDerivationCmd.Flags().BoolP("recursive", "r", false, "Include the dependencies of the specified derivations") - rootCmd.AddCommand(showDerivationCmd) - - addEvaluationFlags(showDerivationCmd) - addFlakeFlags(showDerivationCmd) - addLoggingFlags(showDerivationCmd) - - // TODO positional completion -} diff --git a/completers/nix_completer/cmd/store_copyLog.go b/completers/nix_completer/cmd/store_copyLog.go index b672176a12..5136b2c568 100644 --- a/completers/nix_completer/cmd/store_copyLog.go +++ b/completers/nix_completer/cmd/store_copyLog.go @@ -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" ) @@ -15,6 +16,7 @@ func init() { carapace.Gen(store_copyLogCmd).Standalone() store_copyLogCmd.Flags().String("from", "", "URL of the source Nix store") + store_copyLogCmd.Flags().Bool("stdin", false, "Read installables from the standard input") store_copyLogCmd.Flags().String("to", "", "URL of the destination Nix store") storeCmd.AddCommand(store_copyLogCmd) @@ -22,5 +24,5 @@ func init() { addFlakeFlags(store_copyLogCmd) addLoggingFlags(store_copyLogCmd) - // TODO positional completion + carapace.Gen(store_copyLogCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/store_copySigs.go b/completers/nix_completer/cmd/store_copySigs.go index 2eb4559f5a..b28ac5c9f3 100644 --- a/completers/nix_completer/cmd/store_copySigs.go +++ b/completers/nix_completer/cmd/store_copySigs.go @@ -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" ) @@ -14,6 +15,7 @@ var store_copySigsCmd = &cobra.Command{ func init() { carapace.Gen(store_copySigsCmd).Standalone() + store_copySigsCmd.Flags().Bool("stdin", false, "Read installables from the standard input") store_copySigsCmd.Flags().StringP("substituter", "s", "", "Copy signatures from the specified store") storeCmd.AddCommand(store_copySigsCmd) @@ -21,7 +23,5 @@ func init() { addFlakeFlags(store_copySigsCmd) addLoggingFlags(store_copySigsCmd) - // TODO positional completion - - // TODO positional completion + carapace.Gen(store_copySigsCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/store_delete.go b/completers/nix_completer/cmd/store_delete.go index f6c8609e30..e0b7cca7ba 100644 --- a/completers/nix_completer/cmd/store_delete.go +++ b/completers/nix_completer/cmd/store_delete.go @@ -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" ) @@ -15,11 +16,12 @@ func init() { carapace.Gen(store_deleteCmd).Standalone() store_deleteCmd.Flags().Bool("ignore-liveness", false, "Do not check whether the paths are reachable from a root") + store_deleteCmd.Flags().Bool("stdin", false, "Read installables from the standard input") storeCmd.AddCommand(store_deleteCmd) addEvaluationFlags(store_deleteCmd) addFlakeFlags(store_deleteCmd) addLoggingFlags(store_deleteCmd) - // TODO positional completion + carapace.Gen(store_deleteCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/store_dumpPath.go b/completers/nix_completer/cmd/store_dumpPath.go index 8848c2e4f3..2864941ad9 100644 --- a/completers/nix_completer/cmd/store_dumpPath.go +++ b/completers/nix_completer/cmd/store_dumpPath.go @@ -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" ) @@ -14,11 +15,13 @@ var store_dumpPathCmd = &cobra.Command{ func init() { carapace.Gen(store_dumpPathCmd).Standalone() + store_dumpPathCmd.Flags().Bool("stdin", false, "Read installables from the standard input") + storeCmd.AddCommand(store_dumpPathCmd) addEvaluationFlags(store_dumpPathCmd) addFlakeFlags(store_dumpPathCmd) addLoggingFlags(store_dumpPathCmd) - // TODO positional completion + carapace.Gen(store_dumpPathCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/store_makeContentAddressed.go b/completers/nix_completer/cmd/store_makeContentAddressed.go index e40cfd11f4..7043fefb9b 100644 --- a/completers/nix_completer/cmd/store_makeContentAddressed.go +++ b/completers/nix_completer/cmd/store_makeContentAddressed.go @@ -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" ) @@ -16,6 +17,7 @@ func init() { store_makeContentAddressedCmd.Flags().String("from", "", "URL of the source Nix store") store_makeContentAddressedCmd.Flags().Bool("json", false, "Produce output in JSON format") + store_makeContentAddressedCmd.Flags().Bool("stdin", false, "Read installables from the standard input") store_makeContentAddressedCmd.Flags().String("to", "", "URL of the destination Nix store") storeCmd.AddCommand(store_makeContentAddressedCmd) @@ -24,6 +26,5 @@ func init() { addLoggingFlags(store_makeContentAddressedCmd) // TODO flag completion - - // TODO positional completion + carapace.Gen(store_makeContentAddressedCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/store_repair.go b/completers/nix_completer/cmd/store_repair.go index 998ee23458..975f21596b 100644 --- a/completers/nix_completer/cmd/store_repair.go +++ b/completers/nix_completer/cmd/store_repair.go @@ -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" ) @@ -14,11 +15,13 @@ var store_repairCmd = &cobra.Command{ func init() { carapace.Gen(store_repairCmd).Standalone() + store_repairCmd.Flags().Bool("stdin", false, "Read installables from the standard input") + storeCmd.AddCommand(store_repairCmd) addEvaluationFlags(store_repairCmd) addFlakeFlags(store_repairCmd) addLoggingFlags(store_repairCmd) - // TODO positional completion + carapace.Gen(store_repairCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/store_sign.go b/completers/nix_completer/cmd/store_sign.go index 83052a595f..7c1146735b 100644 --- a/completers/nix_completer/cmd/store_sign.go +++ b/completers/nix_completer/cmd/store_sign.go @@ -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" ) @@ -15,6 +16,7 @@ func init() { carapace.Gen(store_signCmd).Standalone() store_signCmd.Flags().BoolP("key-file", "k", false, "File containing the secret signing key") + store_signCmd.Flags().Bool("stdin", false, "Read installables from the standard input") storeCmd.AddCommand(store_signCmd) addEvaluationFlags(store_signCmd) @@ -25,5 +27,5 @@ func init() { "key-file": carapace.ActionFiles(), }) - // TODO positional completion + carapace.Gen(store_signCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/completers/nix_completer/cmd/store_verify.go b/completers/nix_completer/cmd/store_verify.go index 9cc5f31021..d7800caf2b 100644 --- a/completers/nix_completer/cmd/store_verify.go +++ b/completers/nix_completer/cmd/store_verify.go @@ -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" ) @@ -17,6 +18,7 @@ func init() { store_verifyCmd.Flags().Bool("no-contents", false, "Do not verify the contents of each store path") store_verifyCmd.Flags().Bool("no-trust", false, "Do not verify whether each store path is trusted") store_verifyCmd.Flags().StringP("sigs-needed", "n", "", "Require that each path is signed by at least n different keys") + store_verifyCmd.Flags().Bool("stdin", false, "Read installables from the standard input") store_verifyCmd.Flags().StringP("substituter", "s", "", "Use signatures from the specified store") storeCmd.AddCommand(store_verifyCmd) @@ -24,5 +26,5 @@ func init() { addFlakeFlags(store_verifyCmd) addLoggingFlags(store_verifyCmd) - // TODO positional completion + carapace.Gen(store_verifyCmd).PositionalAnyCompletion(nix.ActionInstallables()) } diff --git a/pkg/actions/tools/nix/develop.go b/pkg/actions/tools/nix/develop.go new file mode 100644 index 0000000000..79e12bbc94 --- /dev/null +++ b/pkg/actions/tools/nix/develop.go @@ -0,0 +1,86 @@ +package nix + +import ( + "encoding/json" + "fmt" + + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace/pkg/style" +) + +type devShellsSchema struct { + DevShells map[string]map[string]struct { + Name string `json:"name"` + } `json:"devShells"` +} + +// ActionDevShells completes a flake and development shells from that flake +func ActionDevShells() carapace.Action { + return carapace.ActionMultiPartsN("#", 2, func(c carapace.Context) carapace.Action { + if len(c.Parts) == 0 { + return ActionFlakes() + } + + return carapace.ActionExecCommand("nix", "flake", "show", "--json", c.Parts[0])(func(output []byte) carapace.Action { + devShells := &devShellsSchema{} + if err := json.Unmarshal(output, devShells); err != nil { + return carapace.ActionMessage(err.Error()) + } + + return actionDevShellsAndSystem(c, devShells) + }) + }) +} + +func getCurrentSystem(c carapace.Context) (string, error) { + output, err := c.Command("nix", "show-config", "--json").Output() + if err != nil { + return "", fmt.Errorf("nix show-config: %w", err) + } + + config := struct { + System struct { + Value string `json:"value"` + } `json:"system"` + }{} + if err := json.Unmarshal(output, &config); err != nil { + return "", fmt.Errorf("nix show-config: %w", err) + } + + return config.System.Value, nil +} + +// Completes . +func actionDevShellsAndSystem(c carapace.Context, devShells *devShellsSchema) carapace.Action { + return carapace.ActionMultiPartsN(".", 2, func(c carapace.Context) carapace.Action { + if len(c.Parts) == 0 { + currentSystem, err := getCurrentSystem(c) + if err != nil { + return carapace.ActionMessage(err.Error()) + } + + systems := make([]string, 0) + for system := range devShells.DevShells { + systems = append(systems, system) + } + + return carapace.ActionValues(systems...).StyleF(func(s string, sc style.Context) string { + if s == currentSystem { + return style.Blue + } + return style.Default + }).Suffix(".") + } + + vals := make([]string, 0) + currentSystem, ok := devShells.DevShells[c.Parts[0]] + if !ok { + return carapace.ActionValues() + } + + for name, value := range currentSystem { + vals = append(vals, name, value.Name) + } + return carapace.ActionValuesDescribed(vals...) + }) +} diff --git a/pkg/actions/tools/nix/develop.nix b/pkg/actions/tools/nix/develop.nix new file mode 100644 index 0000000000..8423c82864 --- /dev/null +++ b/pkg/actions/tools/nix/develop.nix @@ -0,0 +1,2 @@ +package nix +import "github.com/carapace" diff --git a/pkg/actions/tools/nix/flake.go b/pkg/actions/tools/nix/flake.go new file mode 100644 index 0000000000..2b5f360383 --- /dev/null +++ b/pkg/actions/tools/nix/flake.go @@ -0,0 +1,45 @@ +package nix + +import ( + "strings" + "time" + + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace/pkg/style" +) + +// ActionFlakes completes flakes currently available +// +// nixpkgs +// . +func ActionFlakes() carapace.Action { + return carapace.ActionExecCommand("nix", "registry", "list")(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + + vals := make([]string, 0) + // `nix registry list` outputs a blank line after the listings + for _, line := range lines[:len(lines)-1] { + fields := strings.Fields(line) + name := strings.Split(fields[1], ":") + if name[0] == "flake" { + vals = append(vals, name[1], fields[2], styleForRegistry(fields[0])) + } + } + return carapace.Batch( + carapace.ActionValues(".", "..").StyleF(style.ForPath), + carapace.ActionDirectories(), + carapace.ActionStyledValuesDescribed(vals...), + ).ToA() + }).Cache(time.Minute).Suffix("#") +} + +func styleForRegistry(s string) string { + switch s { + case "global": + return style.Blue + case "system": + return style.Yellow + default: + return style.Default + } +} diff --git a/pkg/actions/tools/nix/installables.go b/pkg/actions/tools/nix/installables.go new file mode 100644 index 0000000000..6281af925d --- /dev/null +++ b/pkg/actions/tools/nix/installables.go @@ -0,0 +1,41 @@ +package nix + +import ( + "strings" + + "github.com/carapace-sh/carapace" +) + +// ActionInstallables completes nix packages and flakes +// +// An installable nix derivation can either be a nix package (legacyPackages) +// or a nixosModules output of a flake. There is no completion support implemented +// for flake outputs due to the processing time required, so ActionInstallables +// completes packages from the global/system/user channels available and flake names from the +// global/system/user registry +func ActionInstallables() carapace.Action { + return carapace.ActionMultiParts("#", func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.Batch( + ActionFlakes(), + carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return ActionLocalChannels().Suffix("#") + case 1: + return carapace.ActionMessage("TODO: support branch completion") // TODO support branch completion + default: + return carapace.ActionValues() + } + }), + ).ToA() + + case 1: + return ActionPackages(strings.SplitN(c.Parts[0], "/", 2)[0]) + + default: + return carapace.ActionValues() + } + }) +} diff --git a/pkg/actions/tools/nix/templates.go b/pkg/actions/tools/nix/templates.go new file mode 100644 index 0000000000..f12bbfc2f6 --- /dev/null +++ b/pkg/actions/tools/nix/templates.go @@ -0,0 +1,28 @@ +package nix + +import ( + "encoding/json" + "time" + + "github.com/carapace-sh/carapace" +) + +// ActionTemplates completes the templates outputs of the system template flake +func ActionTemplates() carapace.Action { + return carapace.ActionExecCommand("nix", "flake", "show", "--json", "templates")(func(output []byte) carapace.Action { + templatesSchema := struct { + Templates map[string]struct { + Description string `json:"description"` + } `json:"templates"` + }{} + if err := json.Unmarshal(output, &templatesSchema); err != nil { + return carapace.ActionMessage(err.Error()) + } + + vals := make([]string, 0) + for template, value := range templatesSchema.Templates { + vals = append(vals, template, value.Description) + } + return carapace.ActionValuesDescribed(vals...).Prefix("templates#") + }).Cache(time.Hour) +}