nix(feat): Add argbash bash completion support

This commit is contained in:
Wolfgang Walther
2021-04-18 13:51:39 +02:00
committed by Wolfgang Walther
parent c2df7d8198
commit 2559d32912
9 changed files with 113 additions and 68 deletions
+22 -15
View File
@@ -26,6 +26,7 @@ let
"ARG_POSITIONAL_SINGLE([command], [Command to run])"
"ARG_LEFTOVERS([command arguments])"
];
addCommandCompletion = true;
redirectTixFiles = false; # will be done by sub-command
inRootDir = true;
}
@@ -169,19 +170,25 @@ let
''
${hsieMinimalImports} graph-symbols | ${graphviz}/bin/dot -Tpng -o "$_arg_outfile"
'';
in
buildEnv {
name = "postgrest-devtools";
paths = [
watch.bin
pushCachix.bin
build.bin
run.bin
clean.bin
check.bin
dumpMinimalImports.bin
hsieMinimalImports.bin
hsieGraphModules.bin
hsieGraphSymbols.bin
tools = [
watch
pushCachix
build
run
clean
check
dumpMinimalImports
hsieMinimalImports
hsieGraphModules
hsieGraphSymbols
];
}
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in
buildEnv
{
name = "postgrest-devtools";
paths = builtins.map (tool: tool.bin) tools;
} // { inherit bashCompletion; }
+1 -1
View File
@@ -42,4 +42,4 @@ buildEnv
{
name = "postgrest-docker";
paths = [ load.bin ];
} // { inherit image; }
} // { inherit image; bashCompletion = load.bashCompletion; }
+1 -1
View File
@@ -44,4 +44,4 @@ let
EOF
'';
in
script.bin
script
@@ -13,6 +13,7 @@
{ name
, docs
, args ? [ ]
, addCommandCompletion ? false
, inRootDir ? false
, redirectTixFiles ? true
, withEnv ? null
@@ -46,6 +47,17 @@ let
runCommand "${name}-parser" { }
"${argbash}/bin/argbash -o $out ${argsTemplate}/${name}.m4";
bashCompletion =
runCommand "${name}-completion" { } (
''
${argbash}/bin/argbash --type completion --strip all ${argsTemplate}/${name}.m4 > $out
''
+ lib.optionalString addCommandCompletion ''
sed 's/COMPREPLY.*compgen -o bashdefault .*$/_command/' -i $out
''
);
bin =
writeTextFile {
inherit name;
@@ -111,4 +123,4 @@ let
script =
runCommand name { inherit bin name; } "ln -s $bin/bin/$name $out";
in
script // { inherit bin; }
script // { inherit bin bashCompletion; }
+10 -4
View File
@@ -124,8 +124,14 @@ let
[ "$responseCode" -eq 200 ]
'';
tools = [ github dockerLogin dockerHub dockerHubDescription ];
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in
buildEnv {
name = "postgrest-release";
paths = [ github.bin dockerLogin.bin dockerHub.bin dockerHubDescription.bin ];
}
buildEnv
{
name = "postgrest-release";
paths = builtins.map (tool: tool.bin) tools;
} // { inherit bashCompletion; }
+10 -8
View File
@@ -55,12 +55,14 @@ let
${silver-searcher}/bin/ag -l --vimgrep -g '\.l?hs$' . \
| xargs ${hlint}/bin/hlint -X QuasiQuotes -X NoPatternSynonyms
'';
tools = [ style styleCheck lint ];
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in
buildEnv {
name = "postgrest-devtools";
paths = [
style.bin
styleCheck.bin
lint.bin
];
}
buildEnv
{
name = "postgrest-style";
paths = builtins.map (tool: tool.bin) tools;
} // { inherit bashCompletion; }
+17 -12
View File
@@ -171,6 +171,18 @@ let
sed -i 's|^module \(.*\):|module \1/|g' test/coverage.overlay
'';
tools =
[
testSpec
testSpecIdempotence
testIO
dumpSchema
coverage
coverageDraftOverlay
];
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in
# Create an environment that contains all the utility scripts for running tests
# that we defined above.
@@ -179,19 +191,12 @@ buildEnv
name =
"postgrest-tests";
paths =
[
testSpec.bin
testSpecIdempotence.bin
testIO.bin
dumpSchema.bin
coverage.bin
coverageDraftOverlay.bin
];
}
paths = builtins.map (tool: tool.bin) tools;
} // {
inherit bashCompletion;
# The memory tests have large dependencies (a profiled build of PostgREST)
# and are run less often than the spec tests, so we don't include them in
# the default test environment. We make them available through a separate attribute:
// {
memoryTests = testMemory.bin;
memoryTests = testMemory;
}
+14 -8
View File
@@ -1,7 +1,9 @@
{ buildEnv
{ bashCompletion
, buildEnv
, checkedShellScript
, lib
, postgresqlVersions
, writeTextFile
}:
let
# Wrap the `test/with_tmp_db` script with the required dependencies from Nix.
@@ -16,6 +18,7 @@ let
"ARG_POSITIONAL_SINGLE([command], [Command to run])"
"ARG_LEFTOVERS([command arguments])"
];
addCommandCompletion = true;
inRootDir = true;
redirectTixFiles = false;
}
@@ -66,6 +69,7 @@ let
"ARG_POSITIONAL_SINGLE([command], [Command to run])"
"ARG_LEFTOVERS([command arguments])"
];
addCommandCompletion = true;
inRootDir = true;
}
(lib.concatStringsSep "\n\n" runners);
@@ -73,18 +77,20 @@ let
# Create a `postgrest-with-postgresql-` for each PostgreSQL version
withVersions = builtins.map withTmpDb postgresqlVersions;
tools = [ withAll ] ++ withVersions;
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in
buildEnv
{
name =
"postgrest-with";
"postgrest-withtools";
paths = builtins.map (tool: tool.bin) tools;
} // {
inherit bashCompletion;
paths =
[
withAll.bin
] ++ (builtins.map (v: v.bin) withVersions);
}
# make withTools.latest available for other nix files
// {
latest = withTmpDb (builtins.head postgresqlVersions);
}
+25 -18
View File
@@ -19,6 +19,16 @@ let
lib =
pkgs.lib;
modules =
[
postgrest.devtools
postgrest.style
postgrest.tests
postgrest.withTools
]
++ lib.optional release postgrest.release;
in
lib.overrideDerivation postgrest.env (
base: {
@@ -27,29 +37,26 @@ lib.overrideDerivation postgrest.env (
pkgs.cabal-install
pkgs.cabal2nix
pkgs.postgresql
postgrest.devtools
postgrest.hsie.bin
postgrest.nixpkgsUpgrade
postgrest.style
postgrest.tests
postgrest.withTools
postgrest.nixpkgsUpgrade.bin
]
++ lib.optional memoryTests postgrest.tests.memoryTests
++ lib.optional docker postgrest.docker
++ lib.optional release postgrest.release;
++ modules
++ lib.optional memoryTests postgrest.tests.memoryTests.bin
++ lib.optional docker postgrest.docker;
shellHook =
''
source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh
complete -F _command postgrest-watch
complete -F _command postgrest-with-all
complete -F _command postgrest-with-postgresql-13
complete -F _command postgrest-with-postgresql-12
complete -F _command postgrest-with-postgresql-11
complete -F _command postgrest-with-postgresql-10
complete -F _command postgrest-with-postgresql-9.6
complete -F _command postgrest-with-postgresql-9.5
source ${postgrest.hsie.bashCompletion}
'';
''
+ builtins.concatStringsSep "\n" (
builtins.map (bashCompletion: "source ${bashCompletion}") (
builtins.concatLists (builtins.map (module: module.bashCompletion) modules)
++ [ postgrest.hsie.bashCompletion postgrest.nixpkgsUpgrade.bashCompletion ]
++ lib.optional memoryTests postgrest.tests.memoryTests.bashCompletion
++ lib.optional docker postgrest.docker.bashCompletion
)
);
}
)