Browse Source

add ConfigGroup impl

pull/2/head
James Fenn 1 year ago
parent
commit
c261300b65
6 changed files with 59 additions and 4 deletions
  1. +1
    -0
      .gitignore
  2. +16
    -0
      Makefile
  3. +1
    -0
      dub.json
  4. +0
    -2
      source/app.d
  5. +25
    -2
      source/config.d
  6. +16
    -0
      source/providers.d

+ 1
- 0
.gitignore View File

@@ -4,3 +4,4 @@
.dub/
.DS_Store
aight
aight-test-library

+ 16
- 0
Makefile View File

@@ -0,0 +1,16 @@
.PHONY: all install build test run

all: build test

install: build
sudo cp ./aight /usr/local/bin/git-aight
sudo ln -sf /usr/local/bin/git-aight /usr/local/bin/aight

build:
dub build

test:
dub test

run:
dub run

+ 1
- 0
dub.json View File

@@ -5,6 +5,7 @@
],
"copyright": "Copyright © 2019, Sean Bailey",
"dependencies": {
"dlibgit": "~>0.50.6",
"inilike": "~>1.1.0",
"painlessjson": "~>1.4.0"
},


+ 0
- 2
source/app.d View File

@@ -4,6 +4,4 @@ import providers;

void main(string[] args) {
Config conf = new Config(args);
}

+ 25
- 2
source/config.d View File

@@ -6,9 +6,22 @@ import std.stdio;
import std.path: expandTilde;
import inilike.file;

class ConfigGroup {
string key;
string[string] settings;

this(string key, string[string] settings) {
this.key = key;
this.settings = settings;
}

}

class Config {

string[string] settings;
ConfigGroup[] services;
bool helpWanted;

this(string[] args) {
@@ -42,8 +55,18 @@ class Config {

void initConfigFile(string location) {
IniLikeFile file = new IniLikeFile(location);
foreach (tuple; file.group("settings").byKeyValue()) {
settings[tuple.key] = tuple.value;
foreach (group; file.byGroup()) {
string[string] groupRef;

foreach (tuple; group.byKeyValue()) {
groupRef[tuple.key] = tuple.value;
}

if (group.groupName() == "settings") {
this.settings = groupRef;
} else {
services ~= new ConfigGroup(group.groupName(), groupRef);
}
}
}



+ 16
- 0
source/providers.d View File

@@ -1,9 +1,25 @@
module providers;

import std.stdio;
import std.net.curl: get, HTTP;
import std.string: format;
import std.json: parseJSON;
import painlessjson: fromJSON;
import config: ConfigGroup;

TaskProvider getTaskProvider(ConfigGroup config) {
switch (config.key) {
case "trello":
return new TrelloTaskProvider(
config.settings["apiKey"],
config.settings["apiToken"],
config.settings["boardId"]
);
default:
writeln("Cannot resolve config key %s", config.key);
return null;
}
}

struct CardSymbol {
string id;


Loading…
Cancel
Save