Skip to content

Commit

Permalink
Merge branch 'main' into default-list-today-records
Browse files Browse the repository at this point in the history
  • Loading branch information
aligator authored and aligator committed Jun 13, 2021
2 parents 196087c + b4b7c15 commit ff3c6d9
Show file tree
Hide file tree
Showing 19 changed files with 765 additions and 114 deletions.
File renamed without changes.
50 changes: 49 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,55 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.9.0] - 2021-06-09

### Added
* Add the total tracked time for all listed records to `timetrace list records` (#106)

## [0.8.0] - 2021-06-06

### Added
* Introduce the `--revert` flag for `edit record`, `delete record`, `edit project` and `delete project` (#93)
* Add the overall break time for `timetrace status` (#100)

## [0.7.2] - 2021-06-04

### Fixed
* Fix critical error when starting tracking if there are no existing records (#103)

## [0.7.1] - 2021-06-02

### Fixed
* Fix unhandled error in `edit record` command if there are no tracked records (#96)

## [0.7.0] - 2021-05-30

### Added
* Add support for project modules

### Changed
* Consider project modules when filtering projects (#63)
* Display project modules when listing projects (#70)
* Require parent projects to exist when creating a module (#80)

## [0.6.1] - 2021-05-26

### Fixed
* Fix `timetrace stop` command (#86)

## [0.6.0] - 2021-05-26

### Added
* Add `timetrace edit record` command (#51)
* Add `latest` alias for `timetrace edit record` (#73)

### Changed
* Use an info output for `timetrace status` when there's no active tracking (#65)
* Always adhere to the `use12hours` setting for date- and time input and output (#67)

### Fixed
* Don't allow edting of incomplete records (#69)
* Don't allow re-creation of existing projects (#79)

## [0.5.0] - 2021-05-22

Expand Down
140 changes: 129 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

> timetrace is a simple CLI for tracking your working time.
![CLI screenshot](timetrace.png)
![CLI screenshot 64x16](timetrace.png)

:fire: **New:** [Reverting `edit` and `delete` commands is now possible](#edit-a-record)

## Installation

Expand Down Expand Up @@ -66,7 +68,31 @@ finished your work, stop tracking:
timetrace stop
```

You're also able to delete and edit projects and records (see below).
### Project modules

To refine what part of a project you're working on, timetrace supports _project modules_. These are the exact same thing
as normal projects, except that they have a key in the form `<module>@<project>`.

Creating a `grind-beans` module for the `make-coffee` project is simple:

```
timetrace create project grind-beans@make-coffee
```

The new module will be listed as part of the `make-coffee` project:

```
timetrace list projects
+-----+-------------+-------------+
| # | KEY | MODULES |
+-----+-------------+-------------+
| 1 | make-coffee | grind-beans |
+-----+-------------+-------------+
```

When filtering by projects, for example with `timetrace list records -p make-coffee today`, the modules of that project
will be included.

## Command reference

Expand Down Expand Up @@ -174,7 +200,7 @@ timetrace list records {<YYYY-MM-DD>|today|yesterday}

|Argument|Description|
|-|-|
|`YYYY-MM-DD`|The date of the records to list.|
|`YYYY-MM-DD`|The date of the records to list, or `today` or `yesterday`.|
|today|List today's records.|
|yesterday|List yesterday's records.|

Expand All @@ -191,8 +217,27 @@ Display all records created on May 1st 2021:

```
timetrace list records 2021-05-01
+-----+-------------+---------+-------+------------+
| # | PROJECT | START | END | BILLABLE |
+-----+-------------+---------+-------+------------+
| 1 | my-website | 17:30 | 21:00 | yes |
| 2 | my-website | 08:31 | 17:00 | no |
| 3 | make-coffee | 08:25 | 08:30 | no |
+-----+-------------+---------+-------+------------+
```

Filter records by the `make-coffee` project:
```
timetrace list records 2021-05-01
+-----+-------------+---------+-------+------------+
| # | PROJECT | START | END | BILLABLE |
+-----+-------------+---------+-------+------------+
| 1 | make-coffee | 08:25 | 08:30 | no |
+-----+-------------+---------+-------+------------+
```

This will include records for [project modules](#project-modules) like `grind-beans@make-coffee`.

### Edit a project

**Syntax:**
Expand All @@ -207,6 +252,11 @@ timetrace edit project <KEY>
|-|-|
|`KEY`|The project key.|

**Flags:**
|Flag|Short|Description|
|-|-|-|
|`--revert`|`-r`|Revert the project to it's state prior to the last edit.|

**Example:**

Edit a project called `make-coffee`:
Expand All @@ -215,6 +265,56 @@ Edit a project called `make-coffee`:
timetrace edit project make-coffee
```

:fire: **New:** Restore the project to it's state prior to the last edit:

```
timetrace edit project make-coffee --revert
```

### Edit a record

**Syntax:**

```
timetrace edit record {<KEY>|latest}
```

**Arguments:**

|Argument|Description|
|-|-|
|`KEY`|The project key. `YYYY-MM-DD-HH-MM` by default or `YYYY-MM-DD-HH-MMPM` if [`use12hours` is set](#prefer-12-hour-clock-for-storing-records).|

**Flags:**

|Flag|Short|Description|
|-|-|-|
|`--plus`|`-p`|Add the given duration to the record's end time, e.g. `--plus 1h 10m`|
|`--minus`|`-m`|Subtract the given duration from the record's end time, e.g. `--minus 1h 10m`|
|`--revert`|`-r`|Revert the record to it's state prior to the last edit.|

**Example:**

Edit the latest record. Specifying no flag will open the record in your editor:

```
timetrace edit record latest
```

Add 15 minutes to the end of the record created on May 1st, 3PM:

```
timetrace edit record 2021-05-01-15-00 --plus 15m
```

:fire: **New:** Restore the record to it's state prior to the last edit:

```
timetrace edit record 2021-05-01-15-00 --revert
```

Tip: You can get the record key `2021-05-01-15-00` using [`timetrace list records`](#list-all-records-from-a-date).

### Delete a project

**Syntax:**
Expand All @@ -229,6 +329,11 @@ timetrace delete project <KEY>
|-|-|
|`KEY`|The project key.|

**Flags:**
|Flag|Short|Description|
|-|-|-|
|`--revert`|`-r`|Restore a deleted project.|

**Example:**

Delete a project called `make-coffee`:
Expand All @@ -237,6 +342,12 @@ Delete a project called `make-coffee`:
timetrace delete project make-coffee
```

:fire: **New:** Restore the project to it's pre-deletion state:

```
timetrace delete project make-coffee --revert
```

### Delete a record

**Syntax:**
Expand All @@ -251,9 +362,10 @@ timetrace delete record <YYYY-MM-DD-HH-MM>
|-|-|
|`YYYY-MM-DD-HH-MM`|The start time of the desired record.|

|Flat|Description|
|-|-|
|--yes|Do not ask for confirmation|
|Flag|Short|Description|
|-|-|-|
|`--yes`| |Do not ask for confirmation|
|`--revert`|`-r`|Restore a deleted record.|

**Example:**

Expand All @@ -263,6 +375,12 @@ Delete a record created on May 1st 2021, 3:00 PM:
timetrace delete record 2021-05-01-15-00
```

:fire: **New:** Restore the record to it's pre-deletion state:

```
timetrace delete record 2021-05-01-15-00 --revert
```

### Start tracking

**Syntax:**
Expand Down Expand Up @@ -305,11 +423,11 @@ Print the current tracking status:

```
timetrace status
+-------------+--------------------+---------------+
| PROJECT | WORKED SINCE START | WORKED TODAY |
+-------------+--------------------+---------------+
| make-coffee | 3h25m29.037343s | 7h22m49.5749s |
+-------------+--------------------+---------------+
+-------------------+----------------------+----------------+
| CURRENT PROJECT | WORKED SINCE START | WORKED TODAY |
+-------------------+----------------------+----------------+
| make-coffee | 1h 15min | 4h 30min |
+-------------------+----------------------+----------------+
```

### Stop tracking
Expand Down
38 changes: 37 additions & 1 deletion cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (

var confirmed bool

type deleteOptions struct {
Revert bool
}

func deleteCommand(t *core.Timetrace) *cobra.Command {
delete := &cobra.Command{
Use: "delete",
Expand All @@ -31,17 +35,31 @@ func deleteCommand(t *core.Timetrace) *cobra.Command {
}

func deleteProjectCommand(t *core.Timetrace) *cobra.Command {
var options deleteOptions
deleteProject := &cobra.Command{
Use: "project <KEY>",
Short: "Delete a project",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
key := args[0]
if options.Revert {
if err := t.RevertProject(key); err != nil {
out.Err("Failed to revert project: %s", err.Error())
} else {
out.Info("Project backup restored successfully")
}
return
}

project := core.Project{
Key: key,
}

if err := t.BackupProject(key); err != nil {
out.Err("Failed to backup project before deletion: %s", err.Error())
return
}

if err := t.DeleteProject(project); err != nil {
out.Err("Failed to delete %s", err.Error())
return
Expand All @@ -51,11 +69,13 @@ func deleteProjectCommand(t *core.Timetrace) *cobra.Command {
},
}

deleteProject.PersistentFlags().BoolVarP(&options.Revert, "revert", "r", false, "Restores the record to it's state prior to the last 'delete' command.")

return deleteProject
}

func deleteRecordCommand(t *core.Timetrace) *cobra.Command {

var options deleteOptions
// Depending on the use12hours setting, the command syntax either is
// `record YYYY-MM-DD-HH-MM` or `record YYYY-MM-DD-HH-MMPM`.
use := fmt.Sprintf("record %s", t.Formatter().RecordKeyLayout())
Expand All @@ -71,6 +91,15 @@ func deleteRecordCommand(t *core.Timetrace) *cobra.Command {
return
}

if options.Revert {
if err := t.RevertRecord(start); err != nil {
out.Err("Failed to revert record: %s", err.Error())
} else {
out.Info("Record backup restored successfully")
}
return
}

record, err := t.LoadRecord(start)
if err != nil {
out.Err("Failed to read record: %s", err.Error())
Expand All @@ -85,6 +114,11 @@ func deleteRecordCommand(t *core.Timetrace) *cobra.Command {
}
}

if err := t.BackupRecord(start); err != nil {
out.Err("Failed to backup record before deletion: %s", err.Error())
return
}

if err := t.DeleteRecord(*record); err != nil {
out.Err("Failed to delete %s", err.Error())
return
Expand All @@ -94,6 +128,8 @@ func deleteRecordCommand(t *core.Timetrace) *cobra.Command {
},
}

deleteRecord.PersistentFlags().BoolVarP(&options.Revert, "revert", "r", false, "Restores the record to it's state prior to the last 'delete' command.")

return deleteRecord
}

Expand Down
Loading

0 comments on commit ff3c6d9

Please sign in to comment.