1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

git: difftastic: use 'option' attrset

This will avoid having to enumerate and hard-code default values.
This commit is contained in:
Bruno BELANYI 2025-10-06 14:19:38 +00:00 committed by Austin Horstman
parent ed10023224
commit 929535c308
3 changed files with 48 additions and 78 deletions

View file

@ -330,64 +330,21 @@ in
''; '';
}; };
background = mkOption { options = mkOption {
type = types.enum [ type =
"light" with lib.types;
"dark" attrsOf (oneOf [
]; str
default = "light"; number
example = "dark"; bool
description = '' ]);
Determines whether difftastic should use the lighter or darker colors default = { };
for syntax highlighting. example = {
''; color = "dark";
}; sort-path = true;
tab-width = 8;
color = mkOption { };
type = types.enum [ description = "Configuration options for {command}`difftastic`. See {command}`difft --help`";
"always"
"auto"
"never"
];
default = "auto";
example = "always";
description = ''
Determines when difftastic should color its output.
'';
};
context = mkOption {
type = types.ints.u32;
default = 3;
example = 5;
description = ''
Determines the number of contextual lines to show around changed lines.
'';
};
display = mkOption {
type = types.enum [
"side-by-side"
"side-by-side-show-both"
"inline"
];
default = "side-by-side";
example = "inline";
description = ''
Determines how the output displays - in one column or two columns.
'';
};
extraArgs = mkOption {
type = types.nullOr (types.listOf types.str);
default = null;
example = [
"--tab-width=8"
"--sort-paths"
];
description = ''
Extra command line arguments to pass to {command}`difft`.
'';
}; };
}; };
@ -541,6 +498,26 @@ in
"signer" "signer"
] ]
) )
]
++ (
let
mkRenamed =
opt:
lib.mkRenamedOptionModule
[ "programs" "git" "difftastic" opt ]
[ "programs" "git" "difftastic" "options" opt ];
in
map mkRenamed [
"background"
"color"
"context"
"display"
]
)
++ [
(lib.mkRemovedOptionModule [ "programs" "git" "difftastic" "extraArgs" ] ''
'programs.git.difftastic.extraArgs' has been replaced by 'programs.git.difftastic.options'
'')
]; ];
config = mkIf cfg.enable ( config = mkIf cfg.enable (
@ -849,16 +826,9 @@ in
( (
let let
difftCommand = concatStringsSep " " ( difftCommand = "${lib.getExe cfg.difftastic.package} ${
[ lib.cli.toGNUCommandLineShell { } cfg.difftastic.options
"${lib.getExe cfg.difftastic.package}" }";
"--color ${cfg.difftastic.color}"
"--background ${cfg.difftastic.background}"
"--display ${cfg.difftastic.display}"
"--context ${toString cfg.difftastic.context}"
]
++ (lib.optionals (cfg.difftastic.extraArgs != null) cfg.difftastic.extraArgs)
);
in in
(lib.mkMerge [ (lib.mkMerge [
(mkIf cfg.difftastic.enable { (mkIf cfg.difftastic.enable {

View file

@ -1,9 +1,9 @@
[diff] [diff]
external = "@difftastic@/bin/difft --color always --background dark --display inline --context 5 --tab-width=8 --sort-paths" external = "@difftastic@/bin/difft --background dark --color always --context 5 --display inline --sort-paths --tab-width 8"
tool = "difftastic" tool = "difftastic"
[difftool "difftastic"] [difftool "difftastic"]
cmd = "@difftastic@/bin/difft --color always --background dark --display inline --context 5 --tab-width=8 --sort-paths $LOCAL $REMOTE" cmd = "@difftastic@/bin/difft --background dark --color always --context 5 --display inline --sort-paths --tab-width 8 $LOCAL $REMOTE"
[gpg] [gpg]
format = "openpgp" format = "openpgp"

View file

@ -5,14 +5,14 @@
difftastic = { difftastic = {
enable = true; enable = true;
enableAsDifftool = true; enableAsDifftool = true;
background = "dark"; options = {
color = "always"; background = "dark";
context = 5; color = "always";
display = "inline"; context = 5;
extraArgs = [ display = "inline";
"--tab-width=8" tab-width = 8;
"--sort-paths" sort-paths = true;
]; };
}; };
}; };