From e27b642c68999afe90b5f457f0337ad194fe0b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Jab=C5=82o=C5=84ski?= Date: Sat, 28 Dec 2024 22:48:14 +0100 Subject: [PATCH] chore: initial cleanup --- README.md | 6 +++--- cmd/config.go | 2 +- cmd/root.go | 21 ++++++++++----------- internal/ui/cmds.go | 4 ++-- internal/ui/help.go | 4 ++-- internal/ui/utils.go | 6 +++--- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2d8e96a..2c84211 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ punchout \ jira-url='https://jira.company.com' \ jira-token='XXX' \ jql='assignee = currentUser() AND updatedDate >= -14d ORDER BY updatedDate DESC' \ - jira-time-delta-mins='300' \ + jira-time-delta-mins='300' ``` Both the config file and the command line flags can be used in conjunction, but @@ -114,8 +114,8 @@ General General List Controls - h/ Move cursor up - k/ Move cursor down + k/ Move cursor up + j/ Move cursor down h Go to previous page l Go to next page / Start filtering diff --git a/cmd/config.go b/cmd/config.go index b84c233..b146647 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -8,7 +8,7 @@ type JiraConfig struct { JiraURL *string `toml:"jira_url"` JiraToken *string `toml:"jira_token"` Jql *string - JiraTimeDeltaMins *int `toml:"jira_time_delta_mins"` + JiraTimeDeltaMins int `toml:"jira_time_delta_mins"` } type POConfig struct { diff --git a/cmd/root.go b/cmd/root.go index 3588a39..86d0c3e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -58,13 +58,14 @@ func Execute() { if *jiraTimeDeltaMinsStr != "" { jiraTimeDeltaMins, err = strconv.Atoi(*jiraTimeDeltaMinsStr) if err != nil { - die("could't convert jira-time-delta-mins to a number") + die("couldn't convert jira-time-delta-mins to a number") } } poCfg, err := readConfig(*configFilePath) if err != nil { - die("error reading config at %s: %s", *configFilePath, err.Error()) + fmt.Fprintf(os.Stderr, "error reading config at %s: %s.\n"+ + "continue with command line args only\n", *configFilePath, err.Error()) } if *jiraURL != "" { @@ -79,7 +80,7 @@ func Execute() { poCfg.Jira.Jql = jql } if *jiraTimeDeltaMinsStr != "" { - poCfg.Jira.JiraTimeDeltaMins = &jiraTimeDeltaMins + poCfg.Jira.JiraTimeDeltaMins = jiraTimeDeltaMins } configKeyMaxLen := 40 @@ -90,28 +91,26 @@ func Execute() { fmt.Fprintf(os.Stdout, "%s%s\n", ui.RightPadTrim("JIRA URL", configKeyMaxLen), *poCfg.Jira.JiraURL) fmt.Fprintf(os.Stdout, "%s%s\n", ui.RightPadTrim("JIRA Token", configKeyMaxLen), *poCfg.Jira.JiraToken) fmt.Fprintf(os.Stdout, "%s%s\n", ui.RightPadTrim("JQL", configKeyMaxLen), *poCfg.Jira.Jql) - fmt.Fprintf(os.Stdout, "%s%d\n", ui.RightPadTrim("JIRA Time Delta Mins", configKeyMaxLen), *poCfg.Jira.JiraTimeDeltaMins) + fmt.Fprintf(os.Stdout, "%s%d\n", ui.RightPadTrim("JIRA Time Delta Mins", configKeyMaxLen), poCfg.Jira.JiraTimeDeltaMins) os.Exit(0) } // validations - - if *poCfg.Jira.JiraURL == "" { + if poCfg.Jira.JiraURL == nil || *poCfg.Jira.JiraURL == "" { die("jira-url cannot be empty") } - if *poCfg.Jira.JiraToken == "" { + if poCfg.Jira.JiraToken == nil || *poCfg.Jira.JiraToken == "" { die("jira-token cannot be empty") } - if *poCfg.Jira.Jql == "" { + if poCfg.Jira.Jql == nil || *poCfg.Jira.Jql == "" { die("jql cannot be empty") } db, err := setupDB(dbPathFull) if err != nil { - fmt.Fprintf(os.Stderr, "Couldn't set up punchout database. This is a fatal error\n") - os.Exit(1) + die("couldn't set up punchout database. This is a fatal error\n") } tp := jira.BearerAuthTransport{ @@ -122,6 +121,6 @@ func Execute() { panic(err) } - ui.RenderUI(db, cl, *poCfg.Jira.Jql, *poCfg.Jira.JiraTimeDeltaMins) + ui.RenderUI(db, cl, *poCfg.Jira.Jql, poCfg.Jira.JiraTimeDeltaMins) } diff --git a/internal/ui/cmds.go b/internal/ui/cmds.go index aa7ae53..e6a75b5 100644 --- a/internal/ui/cmds.go +++ b/internal/ui/cmds.go @@ -56,7 +56,7 @@ func insertManualEntry(db *sql.DB, issueKey string, beginTS time.Time, endTS tim stmt, err := db.Prepare(` INSERT INTO issue_log (issue_key, begin_ts, end_ts, comment, active, synced) VALUES (?, ?, ?, ?, ?, ?); - `) +`) if err != nil { return manualEntryInserted{issueKey, err} } @@ -86,7 +86,7 @@ SET begin_ts = ?, end_ts = ?, comment = ? WHERE ID = ?; - `) +`) if err != nil { return manualEntryUpdated{rowID, issueKey, err} } diff --git a/internal/ui/help.go b/internal/ui/help.go index 725a355..d809a7a 100644 --- a/internal/ui/help.go +++ b/internal/ui/help.go @@ -45,8 +45,8 @@ var ( `), helpHeaderStyle.Render("General List Controls"), helpSectionStyle.Render(` - h/ Move cursor up - k/ Move cursor down + k/ Move cursor up + j/ Move cursor down h Go to previous page l Go to next page / Start filtering diff --git a/internal/ui/utils.go b/internal/ui/utils.go index 218042c..12e19fd 100644 --- a/internal/ui/utils.go +++ b/internal/ui/utils.go @@ -33,7 +33,7 @@ func insertNewEntry(db *sql.DB, issueKey string, beginTs time.Time) error { stmt, err := db.Prepare(` INSERT INTO issue_log (issue_key, begin_ts, active, synced) VALUES (?, ?, ?, ?); - `) +`) if err != nil { return err @@ -81,7 +81,7 @@ SELECT ID, issue_key, begin_ts, end_ts, comment, active, synced FROM issue_log WHERE active=false AND synced=false ORDER by end_ts DESC; - `) +`) if err != nil { return nil, err } @@ -115,7 +115,7 @@ SELECT ID, issue_key, begin_ts, end_ts, comment FROM issue_log WHERE active=false AND synced=true ORDER by end_ts DESC LIMIT 30; - `) +`) if err != nil { return nil, err }