Skip to content

Commit 1fa53c6

Browse files
committed
config-schema: add --when and --scope keys
1 parent 5ff828b commit 1fa53c6

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

cli/src/config-schema.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,34 @@
904904
"default": "none"
905905
}
906906
}
907+
},
908+
"--when": {
909+
"type": "object",
910+
"description": "Conditions restriction the application of the configuration",
911+
"properties": {
912+
"repositories": {
913+
"type": "array",
914+
"description": "List of paths to match the repository path prefix",
915+
"items": {
916+
"type": "string"
917+
}
918+
},
919+
"commands": {
920+
"type": "array",
921+
"description": "List of subcommands to match",
922+
"items": {
923+
"type": "string"
924+
}
925+
}
926+
}
927+
},
928+
"--scope": {
929+
"type": "array",
930+
"description": "Scoped tables for conditional configuration",
931+
"items": {
932+
"$comment": "https://json-schema.org/understanding-json-schema/structuring#recursion",
933+
"$ref": "#"
934+
}
907935
}
908936
}
909937
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#:schema ../../../src/config-schema.json
2+
3+
[[--scope]]
4+
--when.repositories = ["~/repos/employer"]
5+
user.email = 5 # should error because it's not a string
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#:schema ../../../src/config-schema.json
2+
3+
# configuring the formatting of timestamps only for the log command
4+
5+
[[--scope]]
6+
--when.commands = ["log"]
7+
template-aliases.'format_timestamp(timestamp)' = 'timestamp.ago()'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#:schema ../../../src/config-schema.json
2+
3+
# --when can be used at the top-level. This is useful when configuration is
4+
# organized over several files.
5+
--when.repositories = ["~/repos/employer"]
6+
7+
# This might be a file that represents all configuration that should apply to
8+
# the set of repositories belonging to an employer. Setting a custom work email
9+
# could be a common use case.
10+
user.email = "[email protected]"

0 commit comments

Comments
 (0)