From 2e5ede21cb33f91231cc7b6ba987cd07b665751a Mon Sep 17 00:00:00 2001 From: Sangelo Date: Fri, 6 Oct 2023 14:01:29 +0200 Subject: [PATCH] Start work on config file --- src/handlers/configHandler.nim | 29 ++++++++++++++++++++++++ src/main.nim | 28 +++++++++++++----------- src/resources/config.toml | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 src/handlers/configHandler.nim create mode 100644 src/resources/config.toml diff --git a/src/handlers/configHandler.nim b/src/handlers/configHandler.nim new file mode 100644 index 0000000..cfe598f --- /dev/null +++ b/src/handlers/configHandler.nim @@ -0,0 +1,29 @@ +import os + +const + dashinitConfig = staticRead("../resources/config.toml") + +proc createConfigFile*() = + var configPath: string + + # Determine the build type + when defined(release): + # Determine the operating system + when defined(windows): + configPath = os.getHomeDir() / "dashinit" / "config.toml" + else: + configPath = os.getHomeDir() / ".config" / "dashinit" / "config.toml" + else: + configPath = getAppFilename().parentDir() / "config.toml" + + # Create the directory if it doesn't exist + let dir = configPath.parentDir() + if not dir.dirExists(): + dir.createDir() + + # Write the template config to the determined path + if not configPath.fileExists(): + writeFile(configPath, dashinitConfig) + +when isMainModule: + createConfigFile() diff --git a/src/main.nim b/src/main.nim index bb22f78..9c9e987 100644 --- a/src/main.nim +++ b/src/main.nim @@ -2,22 +2,24 @@ import os, strutils import subcommands/help import subcommands/init +import handlers/configHandler proc main() = - let args = commandLineParams() - if args.len == 0: - init() - return + createConfigFile() + let args = commandLineParams() + if args.len == 0: + init() + return - let subcommand = args[0].toLower() + let subcommand = args[0].toLower() - case subcommand - of "help": - displayHelp() - of "init": - init() - else: - echo "Unknown argument '", subcommand, "'. Use 'help' for available commands." + case subcommand + of "help": + displayHelp() + of "init": + init() + else: + echo "Unknown argument '", subcommand, "'. Use 'help' for available commands." when isMainModule: - main() + main() diff --git a/src/resources/config.toml b/src/resources/config.toml new file mode 100644 index 0000000..235fe4b --- /dev/null +++ b/src/resources/config.toml @@ -0,0 +1,40 @@ +# dashinit Configuration File + +[general] +# Where to download templates from +template_repo = "https://gitpot.dev/dashinit/templates" + +# The default template to be used when initialising +default_template = "default" + +[templates] +# Allow user scripts to be executed +allow_scripts = false + +# If allow_scripts is set to false, these scripts will still be executable +script_whitelist = [ + "default/default.sh" + # "template/script.sh", + # "~/.local/share/dashinit/scripts/script.sh" # full paths are also possible +] + +[updates] +# Check for updates periodically. Disabled by default +check = false + +# Frequency to check for updates. (daily, weekly, monthly) +# If an unrecognized value is provided, it defaults to 'weekly' +frequency = "weekly" + +[logs] +# Whether logs are enabled or not +enabled = false + +# Specify log level (info, warning, error, debug) +level = "info" + +# Where the logs should be stored +path = "~/.local/share/dashinit/logs" + +# Maximum log size in MB before a new log gets created +max_size = 10 \ No newline at end of file