From d185802c65e24d8491eaf93098846d414ea92d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Mon, 10 Feb 2025 23:59:14 +0100 Subject: [PATCH] Add completions to package --- .envrc | 1 + .gitignore | 2 ++ flake.nix | 8 ++++++++ main.go | 14 ++++++++------ 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .envrc create mode 100644 .gitignore diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..726d2d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +.direnv diff --git a/flake.nix b/flake.nix index 2530268..c55bc7f 100644 --- a/flake.nix +++ b/flake.nix @@ -68,6 +68,13 @@ pname = "natstonotify"; src = src; vendorHash = "sha256-xAFxgUH2QUkmdCXJB4NzURozedgMIyawdf/g3vxOyC0="; + nativeBuildInputs = [ pkgs.installShellFiles ]; + postInstall = '' + installShellCompletion --cmd natstonotify \ + --bash <($out/bin/natstonotify completion bash) \ + --zsh <($out/bin/natstonotify completion zsh) \ + --fish <($out/bin/natstonotify completion fish) + ''; }; } ); @@ -78,6 +85,7 @@ packages = with pkgs; [ go golangci-lint + (self.packages.${pkgs.system}.default) ]; }; } diff --git a/main.go b/main.go index 59bbaff..d064073 100644 --- a/main.go +++ b/main.go @@ -60,8 +60,9 @@ func main() { Usage: "NATS-powered notification service", Commands: []*cli.Command{ { - Name: "server", - Usage: "Start the server", + Name: "server", + Usage: "Start the server", + EnableShellCompletion: true, Action: func(ctx context.Context, cmd *cli.Command) error { b, err := bus.NewNotifyBus() if err != nil { @@ -105,10 +106,11 @@ func main() { }, }, { - Name: "notify", - Aliases: []string{"n"}, - Usage: "Send a notification", - ArgsUsage: "SUMMARY [BODY]", + Name: "notify", + Aliases: []string{"n"}, + Usage: "Send a notification", + ArgsUsage: "SUMMARY [BODY]", + EnableShellCompletion: true, Flags: []cli.Flag{ &cli.BoolFlag{ Name: "local",