Skip to content

Commit

Permalink
feat: favorite specific required_note
Browse files Browse the repository at this point in the history
Added feature where you can now configure a favorite to have a required_note or not. This can override or be overridden by the global required_note flag.
  • Loading branch information
Jeff Lanzarotta committed Feb 5, 2025
1 parent 17fa455 commit e6d5d08
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 39 deletions.
88 changes: 64 additions & 24 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ favorites: <9>
<1> The database file used by Khronos. Default is `.khronos.db`.
<2> If debug type information should be printed to the screen or not. Default is `false`.
<3> Indicated which report to run and which ones to not.
<4> If a note is required when entering a new entry into Khronos. Default is `false`.
<4> If a note is required when entering a new entry into Khronos. Default is `false`. This overrides favorite specific configuration.
<5> The number of minutes to round up or down to when running reports. This makes is easy to report on a consistent time "buckets".
<6> The day used to indicate the start of the week. Some company's week start on Saturday, some on Sunday. This allows to to change that start day to fit your needs. The default is `Sunday`.
<7> Should a daily total be shown for each day when rendering the "by day" report. Default is `true`.
<8> Indicates if work and break time should be split into seperate values during reports or not. The default is `false`.
<8> Indicates if work and break time should be split into separate values during reports or not. The default is `false`.
<9> The list of favorites.

== Natural Language Time
Expand Down Expand Up @@ -171,13 +171,15 @@ During an _interactive_ add, your list of favorites are displayed and you can in
----
Favorites found in configuration file[C:\Users\yourname\.khronos.yaml]:
# | PROJECT+TASK
---+-----------------------------
0 | general+training
1 | general+product development
2 | general+personal time
3 | general+holiday
4 | general+vacation/PTO/Comp
# | PROJECT+TASK | REQUIRE NOTE*
---+-----------------------------+---------------
0 | general+training | false
1 | general+product development | false
2 | general+personal time | false
3 | general+holiday | false
4 | general+vacation/PTO/Comp | false
* May be overridden by global configuration setting
Please enter the number of the favorite; otherwise, [Return] to quit. > 0
----
Expand Down Expand Up @@ -282,7 +284,7 @@ favorites:

==== url

An optional URL can be added to a favorite. This URL will show up on various commands and reports. This URL can be uses to a link to JIRA or any website you need to have linked to favorite.
An optional URL can be added to a favorite. This URL will show up on various commands and reports. This URL can be uses to a link to JIRA or any website you need to have linked to favorite.

Here is an example:

Expand All @@ -301,6 +303,22 @@ favorites:
.
----

==== require_note

An optional `required_note` can be added to a favorite. This flag tells Khronos that you want to require the prompting of a note for this specific favorite.

IMPORTANT: If the global `require_note` option is set to `true`, no matter what value you set on a favorite's `required_note`, a note will be required.

# | PROJECT+TASK | REQUIRE NOTE*
---+-----------------------------+---------------
0 | general+training | true
1 | general+product development | false
2 | general+personal time | false
3 | general+holiday | false
4 | general+vacation/PTO/Comp | false
* May be overridden by global configuration setting
=== amend
The `amend` command tells Khronos that you are wanting to modify a recent entry's information. By default, amend amends the most recent entry's information. How if you would like to get a list of the entries for today, use the `--today` option. More on the `--today` option below.
Expand Down Expand Up @@ -441,13 +459,15 @@ The `favorites` command tells Khronos that you would like to show all your curre
$ k show --favorites
Favorites found in configuration file[C:\Users\yourname\.khronos.yaml]:
# | PROJECT+TASK
---+-----------------------------
0 | general+training
1 | general+product development
2 | general+personal time
3 | general+holiday
4 | general+vacation/PTO/Comp
# | PROJECT+TASK | REQUIRE NOTE*
---+-----------------------------+---------------
0 | general+training | false
1 | general+product development | false
2 | general+personal time | false
3 | general+holiday | false
4 | general+vacation/PTO/Comp | false
* May be overridden by global configuration setting
----
If one or more of your favorites have an associated URL, your favorites will be shown like this:
Expand All @@ -457,13 +477,33 @@ If one or more of your favorites have an associated URL, your favorites will be
$ k show --favorites
Favorites found in configuration file[C:\Users\yourname\.khronos.yaml]:
# | PROJECT+TASK | URL
---+-----------------------------+-------------------------------------------------
0 | general+training | https://yoursite.com/url1
1 | general+product development | https://yoursite.com/url2
2 | general+personal time |
3 | general+holiday |
4 | general+vacation/PTO/Comp |
# | PROJECT+TASK | URL | REQUIRE NOTE*
---+-----------------------------+---------------------------+---------------
0 | general+training | https://yoursite.com/url1 | false
1 | general+product development | https://yoursite.com/url2 | false
2 | general+personal time | | false
3 | general+holiday | | false
4 | general+vacation/PTO/Comp | | false
* May be overridden by global configuration setting
----
If one or more of your favorites have an associated description, your favorites will be shown like this:
[source, shell]
----
$ k show --favorites
Favorites found in configuration file[C:\Users\yourname\.khronos.yaml]:
# | PROJECT+TASK | DESCRIPTION | URL | REQUIRE NOTE*
---+-----------------------------+-------------+---------------------------+---------------
0 | general+training | Training | https://yoursite.com/url1 | false
1 | general+product development | | https://yoursite.com/url2 | false
2 | general+personal time | | | false
3 | general+holiday | | | false
4 | general+vacation/PTO/Comp | | | false
* May be overridden by global configuration setting
----
==== statistics
Expand Down
17 changes: 10 additions & 7 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ package cmd
import (
"bufio"
"fmt"
"khronos/constants"
"log"
"os"
"strconv"
"strings"
"time"
"khronos/constants"

"github.com/agrison/go-commons-lang/stringUtils"
"github.com/fatih/color"
"github.com/dromara/carbon/v2"
"github.com/fatih/color"
"github.com/ijt/go-anytime"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -57,7 +57,7 @@ var addCmd = &cobra.Command{
Use: "add [project+task...]",
Args: cobra.MaximumNArgs(1),
Short: constants.ADD_SHORT_DESCRIPTION,
Long: constants.ADD_LONG_DESCRIPTION,
Long: constants.ADD_LONG_DESCRIPTION,
Run: func(cmd *cobra.Command, args []string) {
runAdd(cmd, args)
},
Expand Down Expand Up @@ -140,6 +140,7 @@ func runAdd(cmd *cobra.Command, args []string) {

var projectTask string = constants.EMPTY
var url string = constants.EMPTY
var requiredNote bool = false

favorite, _ := cmd.Flags().GetInt(constants.FAVORITE)

Expand Down Expand Up @@ -184,6 +185,7 @@ func runAdd(cmd *cobra.Command, args []string) {
var fav Favorite = getFavorite(i)
projectTask = fav.Favorite
url = fav.URL
requiredNote = fav.RequireNote
break
}
}
Expand All @@ -196,11 +198,12 @@ func runAdd(cmd *cobra.Command, args []string) {
os.Exit(1)
}

// Check if the note was empty and the require_note flag is set. If so, require the note.
// Check if the note was empty and the require_note flag is globally set or
// set on the favorite. If so, require the note.
if stringUtils.IsEmpty(note) {
var required bool = viper.GetBool(constants.REQUIRE_NOTE)
if required {
note = promptForNote(required)
var globalRequired bool = viper.GetBool(constants.REQUIRE_NOTE)
if globalRequired || requiredNote {
note = promptForNote(true)

// If the note is still empty, this is an indicator that the user wants to exit.
if len(note) <= 0 {
Expand Down
18 changes: 10 additions & 8 deletions cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Favorite struct {
Favorite string `yaml:"favorite"`
Description string `yaml:"description"`
URL string `yaml:"url"`
RequireNote bool `default:"false" yaml:"require_note"`
}

func init() {
Expand Down Expand Up @@ -135,28 +136,29 @@ func showFavorites() {

t.Style().Options.DrawBorder = false
if descriptionFound && urlFound {
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK, constants.DESCRIPTION, constants.URL})
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK, constants.DESCRIPTION, constants.URL, constants.REQUIRE_NOTE_WITH_ASTERISK})
} else if descriptionFound {
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK, constants.DESCRIPTION})
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK, constants.DESCRIPTION, constants.REQUIRE_NOTE_WITH_ASTERISK})
} else if urlFound {
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK, constants.URL})
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK, constants.URL, constants.REQUIRE_NOTE_WITH_ASTERISK})
} else {
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK})
t.AppendHeader(table.Row{"#", constants.PROJECT_TASK, constants.REQUIRE_NOTE_WITH_ASTERISK})
}

for i, f := range config.Favorites {
if descriptionFound && urlFound {
t.AppendRow(table.Row{i, f.Favorite, f.Description, f.URL})
t.AppendRow(table.Row{i, f.Favorite, f.Description, f.URL, f.RequireNote})
} else if descriptionFound {
t.AppendRow(table.Row{i, f.Favorite, f.Description})
t.AppendRow(table.Row{i, f.Favorite, f.Description, f.RequireNote})
} else if urlFound {
t.AppendRow(table.Row{i, f.Favorite, f.URL})
t.AppendRow(table.Row{i, f.Favorite, f.URL, f.RequireNote})
} else {
t.AppendRow(table.Row{i, f.Favorite})
t.AppendRow(table.Row{i, f.Favorite, f.RequireNote})
}
}

log.Println(t.Render())
log.Printf("\n%s\n", constants.MAY_BE_OVERRIDDEN_BY_GLOBAL_CONFIGURATION_SETTING)
}

func showStatistics() {
Expand Down
2 changes: 2 additions & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const HELLO_LONG_DESCRIPTION = "In order to have khronos start tracking time is
const HELLO_SHORT_DESCRIPTION = "Start time tracking for the day"
const HELP_SHORT_DESCRIPTION = "Show help for command"
const INDENT_AMOUNT int = 4
const MAY_BE_OVERRIDDEN_BY_GLOBAL_CONFIGURATION_SETTING = "* May be overridden by global configuration setting"
const NATURAL_LANGUAGE_DESCRIPTION string = "Natural Language Time, e.g., '18 minutes ago' or '9:45am'"
const NOTE string = "note"
const NOTE_DESCRIPTION string = "A note associated with this entry"
Expand Down Expand Up @@ -109,6 +110,7 @@ const REPORT_CARBON_TO_FROM_FORMAT string = "Y-M-d"
const REPORT_LONG_DESCRIPTION = "When you need to generate a report, default today, use this command."
const REPORT_SHORT_DESCRIPTION = "Generate a report"
const REQUIRE_NOTE string = "require_note"
const REQUIRE_NOTE_WITH_ASTERISK string = "require note*"
const ROOT_LONG_DESCRIPTION = "Khronos is a simple command line tool use to track the time you spend on a specific project and the one or more tasks associated with that project. It was inspired by the concepts of utt (Ultimate Time Tracker) and timetrap."
const ROOT_SHORT_DESCRIPTION = "Simple program used to track time spent on projects and tasks"
const ROUND_TO_MINUTES string = "round_to_minutes"
Expand Down

0 comments on commit e6d5d08

Please sign in to comment.