summaryrefslogtreecommitdiff
path: root/cmd/kzsettings.cpp
blob: 2484e1d6f3bd98c79f41d1c900e74f2455e4a6d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <kzsettings.h>

using namespace std;

int main(int argc, char *argv[])
{
    KaZoe::KzSettings settings;

    if(argc < 2)
    {
        std::cout << "Current settings:"  << std::endl;

        settings.forEach([](const KzSettingKey& key, const KzSettingValue& value) {
            std::string head;
            if(!key.first.empty())
            {
                head = "[" + key.first + "]";
            }
            std::cout << "> " << head << key.second << " = " << KaZoe::valueToStr(value) << std::endl;
        });
    }
    else
    {
        std::string category;
        std::string gkey = argv[1];
        if(gkey.starts_with("["))
        {
            category = gkey.substr(1, gkey.find(']') - 1);
            gkey = gkey.substr(gkey.find(']') + 1);
        }
        if(argc == 2)
        {
            std::cout << KaZoe::valueToStr(settings.get(gkey, category)) << std::endl;
        }
        else if(argc == 3)
        {
            std::string value = argv[2];
            settings.set(gkey, KaZoe::makeValue(value), category);
        }
    }

    return 0;
}