diff options
author | Teddy Wing | 2017-06-04 00:19:35 +0200 |
---|---|---|
committer | Teddy Wing | 2017-06-04 00:19:35 +0200 |
commit | eb82e5e447dff67d5bcd1a2d5c9c52990a840e29 (patch) | |
tree | 62e7231d94124dd3a04325a2db5611e4c58952dd /timetask | |
parent | 7e711772def7a5d711500c3c6c37ea41b57ac598 (diff) | |
download | timetasker-eb82e5e447dff67d5bcd1a2d5c9c52990a840e29.tar.bz2 |
RequestModules(): Pretty print modules
Parse the module XML with `ModuleParseXML()`. Take the resulting
`[]Module` slice and use it to generate a string of the following
format:
ID Module
55555 R&D
77777 Sprint 1
222222 Sprint 2
This string is what gets printed to the console, which makes it rather
easy to read the modules that are available for the given project and
grab the appropriate ID to put into your config file.
Diffstat (limited to 'timetask')
-rw-r--r-- | timetask/http.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/timetask/http.go b/timetask/http.go index 3ff6f4f..575ceae 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -1,6 +1,8 @@ package timetask import ( + "bytes" + "fmt" "io/ioutil" "net/http" "net/http/cookiejar" @@ -160,5 +162,18 @@ func RequestModules( } response_body := string(body) - return response_body, nil + modules, err := ModuleParseXML(response_body) + if err != nil { + return "", err + } + + var module_buf bytes.Buffer + module_buf.WriteString("ID\tModule\n") + for _, module := range modules { + module_buf.WriteString( + fmt.Sprintf("%d\t%s\n", module.ID, module.Name), + ) + } + + return module_buf.String(), nil } |