Start work on config file

This commit is contained in:
Sangelo 2023-10-06 14:01:29 +02:00
parent 2f0caa12f9
commit 2e5ede21cb
3 changed files with 84 additions and 13 deletions

View file

@ -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()

View file

@ -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()

40
src/resources/config.toml Normal file
View file

@ -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