aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 10:29:00 +0200
committerTeddy Wing2017-06-03 10:29:00 +0200
commit13c84cd9973458750305c72a919cf921d9b22b04 (patch)
treee41b65c319c8289dbf6a72264f7602090ff1f857
parent055301ca09d57b759b290d897bbb7560460251ca (diff)
downloadtimetasker-13c84cd9973458750305c72a919cf921d9b22b04.tar.bz2
main.go: Read config from a new format TOML file
Construct a new config format, written in TOML. Read that format in when starting the program. This new format has the benefit of using project name aliases as keys. The goal will be to allow users to send one of those aliases as a command line argument to the program, and thus to have the program post a TimeTask entry for that project. Here's an idea of what the new format looks like: [auth] username = "example" password_cmd = "" [projects.myprojectalias] client = ... project = ... module = ... task = ... work_type = ... time = 7 billable = true [projects.project2] client = ... project = ... module = ... task = ... work_type = ... time = 7 billable = true Eventually, we'll need to remove the `interface{}` from the `Projects` map value and replace it with a real type, but this was just to test that it was possible to get us a nice map from the TOML.
-rw-r--r--main.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/main.go b/main.go
index 5a9f0d1..bfb56b8 100644
--- a/main.go
+++ b/main.go
@@ -8,22 +8,33 @@ import (
"github.com/teddywing/timetasker/timetask"
+ "github.com/BurntSushi/toml"
"gopkg.in/yaml.v2"
)
+// type Config struct {
+// Auth struct {
+// Username string
+// PasswordCmd string `yaml:"password_cmd"`
+// }
+// Fields timetask.Fields
+// Defaults timetask.TimeEntry
+// }
+
type Config struct {
Auth struct {
Username string
- PasswordCmd string `yaml:"password_cmd"`
+ PasswordCmd string //`toml:"password_cmd"`
}
- Fields timetask.Fields
- Defaults timetask.TimeEntry
+ Projects map[string]interface{}
}
var config Config
func main() {
loadConfig()
+ log.Printf("%+v", config)
+ return
if len(os.Args) == 1 {
fmt.Println("Not enough arguments")
@@ -46,13 +57,13 @@ func main() {
// timetask.SubmitTimeEntries(config.Fields, time_entries)
- timetask.GenerateWeeklyTimesheet(os.Stdout, config.Defaults)
+ // timetask.GenerateWeeklyTimesheet(os.Stdout, config.Defaults)
}
func loadConfig() {
- config_str, err := ioutil.ReadFile("config.yml")
+ // config_str, err := ioutil.ReadFile("config2.toml")
config = Config{}
- err = yaml.Unmarshal(config_str, &config)
+ _, err := toml.DecodeFile("config2.toml", &config)
if err != nil {
log.Println(err)
}