From 29ded9426bc98fe083b390ff0726e995f1d40222 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Thu, 23 Nov 2023 18:57:14 +0200 Subject: [PATCH] Add schema to config --- README.adoc | 2 +- config/config-schema.json | 55 +++++++++++++++++++++++++++++++ config.toml => config/config.toml | 8 +++-- 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 config/config-schema.json rename config.toml => config/config.toml (80%) diff --git a/README.adoc b/README.adoc index b4b689a..8b37bc7 100644 --- a/README.adoc +++ b/README.adoc @@ -56,7 +56,7 @@ needs specifically. == Configuration file -See the https://git.korhonen.cc/FunctionalHacker/work-time-calculator/src/branch/main/config.toml[default configuration file] +See the https://git.korhonen.cc/FunctionalHacker/work-time-calculator/src/branch/main/config/config.toml[default configuration file] for more information on how to override configurations. == TODO diff --git a/config/config-schema.json b/config/config-schema.json new file mode 100644 index 0000000..e001123 --- /dev/null +++ b/config/config-schema.json @@ -0,0 +1,55 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "language": { + "type": "string", + "enum": ["en", "fi"] + } + }, + "type": "object", + "properties": { + "language": { + "$ref": "#/definitions/language", + "description": "The language of the application. Currently supported languages are 'en', 'fi'" + }, + "timestampFormat": { + "type": "string", + "description": "Time format used to display timestamps (started, stopped, etc.). Refer to the dayjs documentation on how to set this https://day.js.org/docs/en/display/format" + }, + "defaults": { + "type": "object", + "properties": { + "lunchBreakDuration": { + "type": "string", + "description": "Set as \"00:00\" if you don't have an unpaid lunch break or if you normally log your lunch break hours" + }, + "workDayDuration": { "type": "string", "description": "Your work day duration" }, + "startTime": { "type": "string", "description": "The time you start working" }, + "stopTime": { + "type": ["string", "null"], + "description": "The time you stop working. Can either be 'now' or a time" + } + }, + "required": ["lunchBreakDuration", "workDayDuration", "startTime"], + "additionalProperties": false, + "description": "Default values for inputs" + }, + "askInput": { + "type": "object", + "properties": { + "workDayDuration": { + "type": "boolean", + "description": "Disable prompt for work day duration if set to false" + }, + "startTime": { "type": "boolean", "description": "Disable prompt for start time if set to false" }, + "stopTime": { "type": "boolean", "description": "Disable prompt for stop time if set to false" }, + "logged": { "type": "boolean", "description": "Disable prompt for logged time if set to false" }, + "hadLunch": { "type": "boolean", "description": "Assumed that you didn't have lunch if this is false" } + }, + "additionalProperties": false, + "description": "Settings to disable prompts" + } + }, + "additionalProperties": false, + "description": "Work Time Calculator configuration file. Configuration file location: $XDG_CONFIG_HOME/wtc/config.toml, usually ~/.config/wtc/config.toml" +} diff --git a/config.toml b/config/config.toml similarity index 80% rename from config.toml rename to config/config.toml index aa2338a..034b261 100644 --- a/config.toml +++ b/config/config.toml @@ -1,9 +1,12 @@ +#:schema https://git.korhonen.cc/FunctionalHacker/work-time-calculator/raw/branch/main/config/config-schema.json + # Work Time Calculator configuration file # This is the default configuration. # You can only partially override the config, # any missing values will use the defaults described here. -# You can place your configuration file in $XDG_CONFIG_HOME/wtc/config.toml, +# On Unix/Linux you can place your configuration file in $XDG_CONFIG_HOME/wtc/config.toml, # usually ~/.config/wtc/config.toml +# For windows, I don't know. # The language of the application. # Currently supported languages are "en", "fi" @@ -17,7 +20,7 @@ timestampFormat = "YYYY-MM-DD HH:mm" # This section is for default values for inputs [defaults] -# Leave empty if you don't have an unpaid lunch break +# Set as "00:00" if you don't have an unpaid lunch break # or if you normally log your lunch break hours lunchBreakDuration = "00:30" @@ -25,7 +28,6 @@ lunchBreakDuration = "00:30" workDayDuration = "07:30" # The time you start working - startTime = "08:00" # The time you stop working. Can either be "now" or a time