Skip to content

Commit

Permalink
(wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Apr 6, 2024
1 parent e43ca5e commit eaf7e35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/cmd/time-entry/util/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,23 @@ type timeEntryDefaults struct {
DefaultTimeEntry
}

// FailedToOpenErr error returned when failing to open file without an explicit
// error
var FailedToOpenErr = errors.New("failed to open file")

// Write persists the default values to the folder
func (t *timeEntryDefaults) Write(d DefaultTimeEntry) error {
println(filepath.Join(t.Dir, t.Filename))
f, err := os.Create(filepath.Join(t.Dir, t.Filename))
if err != nil {
return err
}

if f == nil {
return FailedToOpenErr

}

defer f.Close()

if strings.HasSuffix(f.Name(), "json") {
Expand Down Expand Up @@ -111,6 +121,11 @@ func (t *timeEntryDefaults) Read() (DefaultTimeEntry, error) {
dir = nDir
continue
}

if f == nil {
return d, FailedToOpenErr

}
defer f.Close()

if strings.HasSuffix(f.Name(), "json") {
Expand Down

0 comments on commit eaf7e35

Please sign in to comment.