Skip to content

Commit

Permalink
014 Refactor app (#19)
Browse files Browse the repository at this point in the history
* 014 Initialize cobra app

* 014 Customise cobra app

* 014 Initial create command

* 014 Pulling out variables from init section

* 014 Extract version to seperate package

* 014 Add version command

* 014 Remove toggle flag

Did nothing, left over from creation of app.

* 014 Add helpers related to dates

* 014 Convert when to time

* 014 Remove arguments files

* 014 Moved work into model directory

* 014 Add initial tests for date parsing

* 014 Return an error instead of exiting

* 014 Basic test for error state

* 014 Remove todo

Completed yesterday

* 014 Check date with regex instead of by length

* 014 Check expected error message

* 014 Create string after knowing if its valid

* 014 Handle extensions

Both whitespace and other characters.

Whitespace is trimmed out initially so that it is handled cleanly.

Other characters are handled by throwing an error.

* 014 Update test name

* 014 Test for formatting

* 014 Run command and return an error

* 014 Create services folder

* 014 Initialise service and use for create

* 014 Create a repo folder

Add a future implementation in yaml format

* 014 Have the repo used by the service

* 014 Return status code as well as error

Allows for expansion beyond CLI use cases.

* 014 Get author from config and load config via viper

* 014 Delete file holding/reading config

Viper handles this instead now.

* 014 Log if unable to read config

Reverse logic of when to print.

* 014 Implement saving to file system

In a yml format.

* 014 Seperating out logic of getting the worklog directory

* 014 Bump version number

Do this now so that I don't forget.

* 014 Adding in stub repo and service for getting by date

* 014 Get midnight from given time

* 014 Add stub print argument

* 014 Return files from yamlRepo

* 014 Print each log of work

* 014 Bump version
  • Loading branch information
PossibleLlama authored Nov 22, 2020
1 parent f0a0180 commit 3882b69
Show file tree
Hide file tree
Showing 18 changed files with 950 additions and 447 deletions.
115 changes: 0 additions & 115 deletions src/arguments.go

This file was deleted.

107 changes: 0 additions & 107 deletions src/arguments_test.go

This file was deleted.

55 changes: 55 additions & 0 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"time"

"github.com/PossibleLlama/worklog/model"

"github.com/PossibleLlama/worklog/helpers"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var title string
var description string
var when time.Time
var whenString string

// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Create a new record of work",
Long: `Creating a new record of work that
the user has created.`,
RunE: func(cmd *cobra.Command, args []string) error {
when, err := helpers.GetStringAsDateTime(whenString)
if err != nil {
return err
}

work := model.NewWork(title, description, viper.GetString("author"), "", helpers.TimeFormat(when))
_, err = wlService.CreateWorklog(work)
return err
},
}

func init() {
rootCmd.AddCommand(createCmd)

createCmd.Flags().StringVar(
&title,
"title",
"",
"A short description of the work done")
createCmd.Flags().StringVar(
&description,
"description",
"",
"A description of the work")
createCmd.Flags().StringVar(
&whenString,
"when",
helpers.TimeFormat(time.Now()),
"When the work was worked in RFC3339 format")
createCmd.MarkFlagRequired("title")
}
48 changes: 48 additions & 0 deletions src/cmd/print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cmd

import (
"fmt"
"time"

"github.com/PossibleLlama/worklog/helpers"
"github.com/spf13/cobra"
)

var startDate time.Time
var startDateString string

// printCmd represents the print command
var printCmd = &cobra.Command{
Use: "print",
Short: "Print all worklogs since provided date",
Long: `Prints all worklogs to console that have
been created since the start provided date.`,
RunE: func(cmd *cobra.Command, args []string) error {
startDateAnytime, err := helpers.GetStringAsDateTime(startDateString)
startDate = helpers.Midnight(startDateAnytime)
if err != nil {
return err
}

worklogs, _, err := wlService.GetWorklogsSince(startDate)
if err != nil {
return err
}

for _, work := range worklogs {
fmt.Printf("%+v\n", work)
}
return nil
},
}

func init() {
rootCmd.AddCommand(printCmd)

printCmd.Flags().StringVar(
&startDateString,
"startDate",
helpers.TimeFormat(time.Now()),
"Date from which to find worklogs")
printCmd.MarkFlagRequired("startDate")
}
Loading

0 comments on commit 3882b69

Please sign in to comment.