Skip to content

Commit

Permalink
add matrix debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sbreitf1 committed Jan 24, 2025
1 parent aff1584 commit d6ea462
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
argBreakTime = appMain.Flag("break", "Ignore actual break time and take input like '00:45' instead").Short('b').String()
argReminder = appMain.Flag("reminder", "Show desktop notification on target time").Short('r').Bool()
argVerbose = appMain.Flag("verbose", "Print every single step").Short('v').Bool()
argDebug = appMain.Flag("debug", "Maximum debug output").Bool()
argForceReload = appMain.Flag("force-reload", "Do not use existing cache and force refresh of entries").Short('f').Bool()
argCacheTimeSeconds = appMain.Flag("cache-time", "Max cache age in seconds").Default("600").Int()
argDumpColors = appMain.Flag("dump-colors", fmt.Sprintf("Populates %s/colors.json with the current colors", getConfigDir())).Bool()
Expand All @@ -28,6 +29,12 @@ var (
func main() {
kingpin.MustParse(appMain.Parse(os.Args[1:]))

if *argDebug {
*argVerbose = true
matrixDebugPrint = true
matrixOutputFiles = true
matrixOutputFileDir = "."
}
stdio.Verbose = *argVerbose

initColors()
Expand Down
12 changes: 7 additions & 5 deletions matrixfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand All @@ -22,13 +23,14 @@ const (
matrixRendermapTokenCookieName = "oam.Flash.RENDERMAP.TOKEN"
urlMatrixLogin = "/login.jspx"
urlMatrixMainMenu = "/mainMenu.jsf"

matrixDebugPrint = false
matrixOutputFiles = false
)

var (
matrixVersionURL = "/matrix"

matrixDebugPrint = false
matrixOutputFiles = false
matrixOutputFileDir = ""
)

// FetchMatrixEntries returns today's entries available in "Aktuelle Buchungen" in Matrix and the current flexitime balance.
Expand Down Expand Up @@ -163,7 +165,7 @@ func (c *MatrixClient) GetEntries() ([]Entry, error) {
return nil, err
}
if matrixOutputFiles {
if err := os.WriteFile("entries.html", []byte(body), os.ModePerm); err != nil {
if err := os.WriteFile(filepath.Join(matrixOutputFileDir, "entries.html"), []byte(body), os.ModePerm); err != nil {
return nil, fmt.Errorf("output entries file: %s", err.Error())
}
}
Expand Down Expand Up @@ -241,7 +243,7 @@ func (c *MatrixClient) GetFlexiTime() (time.Duration, error) {
return 0, err
}
if matrixOutputFiles {
if err := os.WriteFile("flexitime.html", []byte(body), os.ModePerm); err != nil {
if err := os.WriteFile(filepath.Join(matrixOutputFileDir, "flexitime.html"), []byte(body), os.ModePerm); err != nil {
return 0, fmt.Errorf("output flexitime file: %s", err.Error())
}
}
Expand Down
1 change: 1 addition & 0 deletions userconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type UserConfig struct {

func ReadUserConfig() (UserConfig, error) {
configDir := getConfigDir()
matrixOutputFileDir = configDir
userConfFile := filepath.Join(configDir, "userconfig.json")

data, err := os.ReadFile(userConfFile)
Expand Down

0 comments on commit d6ea462

Please sign in to comment.