mirror of
https://gitlab.com/TECHNOFAB/soonix.git
synced 2026-02-02 15:25:05 +01:00
feat!: add cli with update and list subcommands + gitignore param
This commit is contained in:
parent
56f281eea4
commit
b39e16ec3c
6 changed files with 201 additions and 84 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
# Generated by soonix, DO NOT EDIT
|
# Generated by soonix, DO NOT EDIT
|
||||||
include:
|
include:
|
||||||
- component: gitlab.com/TECHNOFAB/nix-gitlab-ci/nix-gitlab-ci@3.0.0-alpha.2
|
- component: gitlab.com/TECHNOFAB/nix-gitlab-ci/nix-gitlab-ci@3.1.2
|
||||||
inputs:
|
inputs:
|
||||||
version: 3.0.0-alpha.2
|
version: 3.1.2
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
},
|
},
|
||||||
"postUpgradeTasks": {
|
"postUpgradeTasks": {
|
||||||
"commands": [
|
"commands": [
|
||||||
"nix-portable nix run .#soonix:update"
|
"nix-portable nix run .#soonix -- update --skip-gitignore"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,4 +102,3 @@ Soonix is designed as a cleaner, more maintainable alternative to Nixago:
|
||||||
Ready to start using Soonix? Check out the [Usage Guide](./usage.md) for detailed
|
Ready to start using Soonix? Check out the [Usage Guide](./usage.md) for detailed
|
||||||
setup instructions and examples, or browse the [Integration Guide](./integrations.md)
|
setup instructions and examples, or browse the [Integration Guide](./integrations.md)
|
||||||
to see how to use Soonix with different development tools and frameworks.
|
to see how to use Soonix with different development tools and frameworks.
|
||||||
|
|
||||||
|
|
|
||||||
118
lib/module.nix
118
lib/module.nix
|
|
@ -146,16 +146,24 @@ in {
|
||||||
Packages for updating the hooks without a devshell. (readonly)
|
Packages for updating the hooks without a devshell. (readonly)
|
||||||
'';
|
'';
|
||||||
example = {
|
example = {
|
||||||
"soonix:update" = "<derivation>";
|
"soonix" = "<derivation>";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
hooks = config.hooks;
|
hooks = config.hooks;
|
||||||
hookNames = builtins.attrNames hooks;
|
# allow excluding gitignore since stuff like renovate can't use/commit it anyways
|
||||||
|
getHookNames = {includeGitignored ? true}:
|
||||||
|
if includeGitignored
|
||||||
|
then (builtins.attrNames hooks)
|
||||||
|
else
|
||||||
|
map
|
||||||
|
(hook: hook.name)
|
||||||
|
(builtins.filter (hook: !hook.hook.gitignore) (builtins.attrValues hooks));
|
||||||
|
|
||||||
runHooks = concatMapStringsSep "\n" (hookName: let
|
runHooks = args:
|
||||||
|
concatMapStringsSep "\n" (hookName: let
|
||||||
hook = hooks.${hookName};
|
hook = hooks.${hookName};
|
||||||
modes = {
|
modes = {
|
||||||
link =
|
link =
|
||||||
|
|
@ -193,6 +201,7 @@ in {
|
||||||
''
|
''
|
||||||
else "";
|
else "";
|
||||||
in
|
in
|
||||||
|
builtins.addErrorContext "[soonix] while generating script for ${hookName}"
|
||||||
# sh
|
# sh
|
||||||
''
|
''
|
||||||
# Process hook: ${hookName}
|
# Process hook: ${hookName}
|
||||||
|
|
@ -227,9 +236,10 @@ in {
|
||||||
_soonix_failed+=("${hookName}")
|
_soonix_failed+=("${hookName}")
|
||||||
}
|
}
|
||||||
'')
|
'')
|
||||||
hookNames;
|
(getHookNames args);
|
||||||
|
|
||||||
generatedShellHook =
|
generateShellHook = args:
|
||||||
|
builtins.addErrorContext "[soonix] while generating shell hook"
|
||||||
# sh
|
# sh
|
||||||
''
|
''
|
||||||
_soonix_log() {
|
_soonix_log() {
|
||||||
|
|
@ -265,7 +275,7 @@ in {
|
||||||
_soonix_failed=()
|
_soonix_failed=()
|
||||||
_soonix_uptodate=()
|
_soonix_uptodate=()
|
||||||
|
|
||||||
${runHooks}
|
${runHooks args}
|
||||||
|
|
||||||
local output=$'\E[msoonix:\E[38;5;8m'
|
local output=$'\E[msoonix:\E[38;5;8m'
|
||||||
local status=0
|
local status=0
|
||||||
|
|
@ -297,8 +307,8 @@ in {
|
||||||
in rec {
|
in rec {
|
||||||
# nothing to do if no hooks exist
|
# nothing to do if no hooks exist
|
||||||
shellHook =
|
shellHook =
|
||||||
if (builtins.length hookNames > 0)
|
if (builtins.length (builtins.attrNames config.hooks) > 0)
|
||||||
then generatedShellHook
|
then generateShellHook {}
|
||||||
else "";
|
else "";
|
||||||
shellHookFile = pkgs.writeShellScript "shellHook" shellHook;
|
shellHookFile = pkgs.writeShellScript "shellHook" shellHook;
|
||||||
devshellModule = {
|
devshellModule = {
|
||||||
|
|
@ -307,11 +317,99 @@ in {
|
||||||
};
|
};
|
||||||
finalFiles = buildAllFiles allFiles;
|
finalFiles = buildAllFiles allFiles;
|
||||||
# make it simpler to update the hooks without any devshell
|
# make it simpler to update the hooks without any devshell
|
||||||
packages."soonix:update" = pkgs.writeShellScriptBin "soonix:update" ''
|
packages = {
|
||||||
|
soonix =
|
||||||
|
pkgs.writeShellScriptBin "soonix"
|
||||||
|
# sh
|
||||||
|
''
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SKIP_GITIGNORE=false
|
||||||
|
COMMAND=""
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
cat << EOF
|
||||||
|
soonix - Declarative file management tool
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
soonix <COMMAND> [OPTIONS]
|
||||||
|
|
||||||
|
COMMANDS:
|
||||||
|
update Update all managed files
|
||||||
|
list List all managed file targets
|
||||||
|
help Show this help message
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
--skip-gitignore Skip files that would be added to .gitignore
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
soonix update # Update all files
|
||||||
|
soonix update --skip-gitignore # Update only non-gitignored files
|
||||||
|
soonix list # List all targets
|
||||||
|
soonix list --skip-gitignore # List only non-gitignored targets
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
update|list|help)
|
||||||
|
COMMAND="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--skip-gitignore)
|
||||||
|
SKIP_GITIGNORE=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: Unknown argument '$1'" >&2
|
||||||
|
echo ""
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "$COMMAND" ]]; then
|
||||||
|
echo "Error: No command specified" >&2
|
||||||
|
echo ""
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$COMMAND" in
|
||||||
|
help)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
${concatMapStringsSep "\n" (hookName: let
|
||||||
|
hook = hooks.${hookName};
|
||||||
|
in ''
|
||||||
|
if [[ "$SKIP_GITIGNORE" == "true" && "${
|
||||||
|
if hook.hook.gitignore
|
||||||
|
then "true"
|
||||||
|
else "false"
|
||||||
|
}" == "true" ]]; then
|
||||||
|
: # skip
|
||||||
|
else
|
||||||
|
echo "${hook.output}"
|
||||||
|
fi
|
||||||
|
'') (builtins.attrNames hooks)}
|
||||||
|
;;
|
||||||
|
update)
|
||||||
|
if [[ "$SKIP_GITIGNORE" == "true" ]]; then
|
||||||
function _soonix() {
|
function _soonix() {
|
||||||
${shellHook}
|
${generateShellHook {includeGitignored = false;}}
|
||||||
}
|
}
|
||||||
_soonix
|
_soonix
|
||||||
|
else
|
||||||
|
function _soonix() {
|
||||||
|
${generateShellHook {}}
|
||||||
|
}
|
||||||
|
_soonix
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ in
|
||||||
data = {
|
data = {
|
||||||
extends = ["config:recommended"];
|
extends = ["config:recommended"];
|
||||||
postUpgradeTasks.commands = [
|
postUpgradeTasks.commands = [
|
||||||
"nix-portable nix run .#soonix:update"
|
"nix-portable nix run .#soonix -- update --skip-gitignore"
|
||||||
];
|
];
|
||||||
lockFileMaintenance = {
|
lockFileMaintenance = {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,26 @@ in {
|
||||||
assert_file_contains ${shellHook} "gomplate"
|
assert_file_contains ${shellHook} "gomplate"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
name = "packages";
|
||||||
|
type = "script";
|
||||||
|
script = let
|
||||||
|
conf = (soonix.make {inherit hooks;}).config;
|
||||||
|
soonixBin = conf.packages.soonix + "/bin/soonix";
|
||||||
|
in
|
||||||
|
# sh
|
||||||
|
''
|
||||||
|
${ntlib.helpers.path [pkgs.gnugrep]}
|
||||||
|
${ntlib.helpers.scriptHelpers}
|
||||||
|
|
||||||
|
assert -f "${soonixBin}" "should exist"
|
||||||
|
|
||||||
|
assert_file_contains "${soonixBin}" "gotmpl"
|
||||||
|
assert_file_contains "${soonixBin}" "test.json"
|
||||||
|
|
||||||
|
assert_file_contains "${soonixBin}" "SKIP_GITIGNORE"
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue