Преглед на файлове

nixpkgs/elvish: update carapace-bin 0.19.0 -> 0.20.2

Also updates the nix-build patch
Thomas Dy преди 2 години
родител
ревизия
8c57eba407
променени са 2 файла, в които са добавени 93 реда и са изтрити 59 реда
  1. 90 56
      .config/nixpkgs/elvish/carapace-nix-build.patch
  2. 3 3
      .config/nixpkgs/elvish/flake.nix

+ 90 - 56
.config/nixpkgs/elvish/carapace-nix-build.patch

@@ -1,15 +1,9 @@
-commit 29cf307f93c19325ff09f0e324624abd4f6bb7ba
-Author: Thomas Dy <thatsmydoing@gmail.com>
-Date:   Sun Jan 15 18:05:45 2023 +0900
-
-    nix-build: add initial support
-
 diff --git a/completers/nix-build_completer/cmd/root.go b/completers/nix-build_completer/cmd/root.go
 new file mode 100644
-index 00000000..65381edd
+index 00000000..544f0c3c
 --- /dev/null
 +++ b/completers/nix-build_completer/cmd/root.go
-@@ -0,0 +1,39 @@
+@@ -0,0 +1,43 @@
 +package cmd
 +
 +import (
@@ -31,23 +25,27 @@ index 00000000..65381edd
 +func init() {
 +	carapace.Gen(rootCmd).Standalone()
 +
++	rootCmd.Flags().StringP("attr", "A", "", "Attribute to build")
++	rootCmd.Flags().Bool("dry-run", false, "Show what store paths would be built or downloaded")
 +	rootCmd.Flags().StringP("include", "I", "", "Include paths")
 +	rootCmd.Flags().Bool("no-out-link", false, "Do not create a symlink to the output path")
 +	rootCmd.Flags().StringP("out-link", "o", "", "Change the name of the symlink to the output path")
-+	rootCmd.Flags().Bool("dry-run", false, "Show what store paths would be built or downloaded")
-+	rootCmd.Flags().StringP("attr", "A", "", "Attribute to build")
 +	// TODO support --arg and --argstr
 +
-+	carapace.Gen(rootCmd).PositionalAnyCompletion(nix.ActionPaths())
 +	carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
-+		"attr": nix.ActionAttr(rootCmd, func(_ *cobra.Command, c carapace.Context) string {
++		"attr": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
++			opts := nix.AttributeOpts{Source: "default.nix", Include: rootCmd.Flag("include").Value.String()}
 +			if len(c.Args) > 0 {
-+				return c.Args[0]
-+			} else {
-+				return "default.nix"
++				opts.Source = c.Args[0]
 +			}
++			return nix.ActionAttributes(opts)
 +		}),
 +	})
++
++	carapace.Gen(rootCmd).PositionalAnyCompletion(
++		nix.ActionPaths(),
++	)
++
 +}
 diff --git a/completers/nix-build_completer/main.go b/completers/nix-build_completer/main.go
 new file mode 100644
@@ -62,12 +60,25 @@ index 00000000..a733fad2
 +func main() {
 +	cmd.Execute()
 +}
-diff --git a/pkg/actions/tools/nix/attr.go b/pkg/actions/tools/nix/attr.go
+diff --git a/completers/nix-channel_completer/cmd/root.go b/completers/nix-channel_completer/cmd/root.go
+index 4da5434f..1fd1ba5d 100644
+--- a/completers/nix-channel_completer/cmd/root.go
++++ b/completers/nix-channel_completer/cmd/root.go
+@@ -34,7 +34,7 @@ func init() {
+ 			} else if rootCmd.Flag("add").Changed {
+ 				switch len(c.Args) {
+ 				case 0:
+-					return nix.ActionRemoteChannels()
++					return nix.ActionRemoteChannels().Invoke(c).Prefix("https://nixos.org/channels/").ToA()
+ 				case 1:
+ 					return nix.ActionLocalChannels()
+ 				}
+diff --git a/pkg/actions/tools/nix/attribute.go b/pkg/actions/tools/nix/attribute.go
 new file mode 100644
-index 00000000..921bf2b6
+index 00000000..188d0820
 --- /dev/null
-+++ b/pkg/actions/tools/nix/attr.go
-@@ -0,0 +1,82 @@
++++ b/pkg/actions/tools/nix/attribute.go
+@@ -0,0 +1,89 @@
 +package nix
 +
 +import (
@@ -78,41 +89,47 @@ index 00000000..921bf2b6
 +	"strings"
 +
 +	"github.com/rsteube/carapace"
-+	"github.com/spf13/cobra"
 +)
 +
-+//go:embed attrComplete.nix
-+var attrCompleteScript string
++//go:embed attributeComplete.nix
++var attributeCompleteScript string
++
++type AttributeOpts struct {
++	Source  string
++	Include string
++}
 +
-+func ActionAttr(cmd *cobra.Command, getSource func(*cobra.Command, carapace.Context) string) carapace.Action {
++// ActionAttributes completes attributes
++//
++//	firefox
++//	git
++func ActionAttributes(opts AttributeOpts) carapace.Action {
 +	return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
-+		attrPath := c.CallbackValue
-+		nixPath := ""
-+		if cmd.Flag("include").Changed {
-+			nixPath = cmd.Flag("include").Value.String()
++		if opts.Source == "" {
++			opts.Source = "default.nix"
 +		}
 +
-+		source := getSource(cmd, c)
++		attrPath := c.CallbackValue
 +
-+		if strings.HasPrefix(source, "<") {
++		if strings.HasPrefix(opts.Source, "<") {
 +			// expression is a local channel, use as-is
-+		} else if strings.HasPrefix(source, "http:") || strings.HasPrefix(source, "https:") {
++		} else if strings.HasPrefix(opts.Source, "http:") || strings.HasPrefix(opts.Source, "https:") {
 +			// expression is a url, wrap in fetchTarball
-+			source = fmt.Sprintf("(fetchTarball %s)", source)
-+		} else if strings.HasPrefix(source, "channel:") {
++			opts.Source = fmt.Sprintf("(fetchTarball %s)", opts.Source)
++		} else if strings.HasPrefix(opts.Source, "channel:") {
 +			// expression is a channel alias, convert to url
-+			channelName := source[8:]
-+			source = fmt.Sprintf("(fetchTarball https://nixos.org/channels/%s/nixexprs.tar.xz)", channelName)
++			channelName := opts.Source[8:]
++			opts.Source = fmt.Sprintf("(fetchTarball https://nixos.org/channels/%s/nixexprs.tar.xz)", channelName)
 +		} else {
 +			// expression is a local file
-+			filePath := path.Clean(source)
++			filePath := path.Clean(opts.Source)
 +			if path.Base(filePath) == filePath {
 +				// paths must have at least one `/`
 +				filePath = fmt.Sprintf("./%s", filePath)
 +			}
-+			source = filePath
++			opts.Source = filePath
 +		}
-+		expression := fmt.Sprintf("import %s", source)
++		expression := fmt.Sprintf("import %s", opts.Source)
 +
 +		// nix itself handles quotes weirdly so we just avoid them altogether
 +		if strings.Contains(attrPath, "\"") {
@@ -129,32 +146,33 @@ index 00000000..921bf2b6
 +
 +		args := []string{
 +			"--eval", "--json",
-+			"--expr", attrCompleteScript,
++			"--expr", attributeCompleteScript,
 +			"--arg", "__carapaceInput__", expression,
 +			"--argstr", "__carapaceAttrPath__", attrPath,
 +		}
-+		if nixPath != "" {
-+			args = append(args, "-I", nixPath)
++		if opts.Include != "" {
++			args = append(args, "-I", opts.Include)
 +		}
 +		// TODO handle passing through --arg and --argstr from original command
 +
 +		return carapace.ActionExecCommand("nix-instantiate", args...)(func(output []byte) carapace.Action {
 +			var data []string
 +			json.Unmarshal(output, &data)
++
++			prefix := ""
 +			if attrPath != "" {
-+				for i, value := range data {
-+					data[i] = fmt.Sprintf("%s.%s", attrPath, value)
-+				}
++				prefix = fmt.Sprintf("%s.", attrPath)
 +			}
-+			return carapace.ActionValues(data...)
++
++			return carapace.ActionValues(data...).Prefix(prefix).NoSpace()
 +		})
 +	})
 +}
-diff --git a/pkg/actions/tools/nix/attrComplete.nix b/pkg/actions/tools/nix/attrComplete.nix
+diff --git a/pkg/actions/tools/nix/attributeComplete.nix b/pkg/actions/tools/nix/attributeComplete.nix
 new file mode 100644
 index 00000000..4f98d858
 --- /dev/null
-+++ b/pkg/actions/tools/nix/attrComplete.nix
++++ b/pkg/actions/tools/nix/attributeComplete.nix
 @@ -0,0 +1,25 @@
 +all@{ __carapaceInput__, __carapaceAttrPath__, ... }:
 +let
@@ -181,12 +199,26 @@ index 00000000..4f98d858
 +    builtins.attrNames result
 +  else
 +    []
+diff --git a/pkg/actions/tools/nix/channel.go b/pkg/actions/tools/nix/channel.go
+index 930da5a9..62c5ffd4 100644
+--- a/pkg/actions/tools/nix/channel.go
++++ b/pkg/actions/tools/nix/channel.go
+@@ -63,8 +63,6 @@ func ActionRemoteChannels() carapace.Action {
+ 		for _, result := range response.Data.Result {
+ 			vals = append(vals, result.Metric.Channel, result.Metric.Status, styleForStatus(result.Metric.Status))
+ 		}
+-		return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
+-			return carapace.ActionStyledValuesDescribed(vals...).Invoke(c).Prefix("https://nixos.org/channels/").ToA()
+-		})
++		return carapace.ActionStyledValuesDescribed(vals...)
+ 	})
+ }
 diff --git a/pkg/actions/tools/nix/path.go b/pkg/actions/tools/nix/path.go
 new file mode 100644
-index 00000000..e3dbc8b2
+index 00000000..1bacd46c
 --- /dev/null
 +++ b/pkg/actions/tools/nix/path.go
-@@ -0,0 +1,29 @@
+@@ -0,0 +1,31 @@
 +package nix
 +
 +import (
@@ -204,15 +236,17 @@ index 00000000..e3dbc8b2
 +//   - a local channel (<nixpkgs>)
 +func ActionPaths() carapace.Action {
 +	return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
-+		arg := c.CallbackValue
-+		if strings.HasPrefix(arg, "<") {
-+			return ActionLocalChannels().Invoke(c).Prefix("<").Suffix(">").ToA()
-+		} else if strings.HasPrefix(arg, "http:") || strings.HasPrefix(arg, "https:") {
-+			return carapace.ActionValues()
-+		} else if strings.HasPrefix(arg, "channel:") {
-+			return ActionRemoteChannels().Invoke(c).Prefix("channel:").ToA()
++		batch := carapace.Batch(
++			ActionLocalChannels().Prefix("<").Suffix(">"),
++			carapace.ActionFiles(),
++		)
++
++		if !strings.HasPrefix(c.CallbackValue, "channel:") {
++			batch = append(batch, carapace.ActionValues("channel:").NoSpace())
 +		} else {
-+			return carapace.ActionFiles()
++			batch = append(batch, ActionRemoteChannels().Prefix("channel:"))
 +		}
++
++		return batch.ToA()
 +	})
 +}

+ 3 - 3
.config/nixpkgs/elvish/flake.nix

@@ -13,13 +13,13 @@
         };
         buildGoModule rec {
           pname = "carapace-bin";
-          version = "0.19.0";
+          version = "0.20.2";
 
           src = fetchFromGitHub {
             owner = "rsteube";
             repo = "carapace-bin";
             rev = "v${version}";
-            sha256 = "sha256-Bdtuehfp81fq1ZSV+7jwSmxViu8FzVbBGoZ2HfDda5g=";
+            hash = "sha256-UPm0B3sv2+0/tS7NdqY5fpvMbI9B7CxixWF9M74H5w0=";
           };
 
           ldflags = [ "-s" "-w" ];
@@ -37,7 +37,7 @@
             go generate ./...
           '';
 
-          vendorSha256 = "sha256-WXntyDbpGEXHkYgv21vN/JG/CVn6SqnMhmgXfFEQ9eM=";
+          vendorSha256 = "sha256-l4DG6sZyFqu4OlxxL6mmcXTGljxY7xk5u5QlOr8dBNI=";
         };
 
       packages.x86_64-linux.elvish =