From 7106e071efd0c9d4dc2e0793536b5aa08e1e1e9b Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Wed, 12 Jan 2022 20:35:16 -0300 Subject: [PATCH] feat: show and report defaults --- CHANGELOG.md | 7 +++++++ cmd/logInProgress.go | 7 ++++--- cmd/report.go | 20 ++++++++++++-------- cmd/show.go | 11 ++++++++--- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5aba98..bfb91bcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- `show` subcommand has its parameter as optional, and shows current time entry by default when the + parameter is omitted. +- `report` subcommand has its parameters as optional, and use `today` as value when none is set. +- `log in-progress` subcommand is deprecated in favor of `show`/`show current` + ## [v0.28.0] - 2022-01-10 ### Changed diff --git a/cmd/logInProgress.go b/cmd/logInProgress.go index 4995a32b..e062a742 100644 --- a/cmd/logInProgress.go +++ b/cmd/logInProgress.go @@ -23,9 +23,10 @@ import ( // logInProgressCmd represents the logInProgress command var logInProgressCmd = &cobra.Command{ - Use: "in-progress", - Aliases: []string{"current", "open", "running"}, - Short: "Show time entry in progress (if any)", + Use: "in-progress", + Aliases: []string{"current", "open", "running"}, + Short: "Show time entry in progress (if any)", + Deprecated: "use show current instead", RunE: withClockifyClient(func(cmd *cobra.Command, args []string, c *api.Client) error { te, err := c.GetHydratedTimeEntryInProgress(api.GetTimeEntryInProgressParam{ Workspace: viper.GetString(WORKSPACE), diff --git a/cmd/report.go b/cmd/report.go index dd8d0a52..ca84d444 100644 --- a/cmd/report.go +++ b/cmd/report.go @@ -29,17 +29,21 @@ import ( // reportCmd represents the reports command var reportCmd = &cobra.Command{ - Use: "report []", - Short: `List all time entries in the date ranges and with more data (format date as 2016-01-02)`, - Args: cobra.RangeArgs(1, 2), + Use: "report [] []", + Short: "List all time entries in the date ranges and with more data (format date as 2016-01-02)\n" + + "If no parameter is set, shows today's time entries", + Args: cobra.MaximumNArgs(2), PreRunE: printMultipleTimeEntriesPreRun, - RunE: withClockifyClient(func(cmd *cobra.Command, args []string, c *api.Client) error { - start, err := time.Parse("2006-01-02", args[0]) - if err != nil { - return err + RunE: withClockifyClient(func(cmd *cobra.Command, args []string, c *api.Client) (err error) { + start := time.Now() + if len(args) > 0 { + start, err = time.Parse("2006-01-02", args[0]) + if err != nil { + return err + } } - end := start + end := start if len(args) > 1 { end, err = time.Parse("2006-01-02", args[1]) if err != nil { diff --git a/cmd/show.go b/cmd/show.go index 9aa4c470..aeb226ac 100644 --- a/cmd/show.go +++ b/cmd/show.go @@ -25,16 +25,21 @@ import ( var showCmd = &cobra.Command{ Use: "show [current|last||^n]", ValidArgs: []string{"current", "last"}, - Args: cobra.ExactArgs(1), - Short: "Show detailed information about one time entry", + Args: cobra.MaximumNArgs(1), + Short: "Show detailed information about one time entry.\nShows current one by default", RunE: withClockifyClient(func(cmd *cobra.Command, args []string, c *api.Client) error { userID, err := getUserId(c) if err != nil { return err } + id := "current" + if len(args) > 0 { + id = args[0] + } + tei, err := getTimeEntry( - args[0], + id, viper.GetString(WORKSPACE), userID, false,