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