Browse Source

implemented list with and without details, delete (rm), showHoursByDays

pull/1/head
arnaucode 7 years ago
parent
commit
d04a945123
5 changed files with 154 additions and 19 deletions
  1. +52
    -8
      README.md
  2. +47
    -10
      main.go
  3. +55
    -1
      work.go
  4. BIN
      wtt
  5. BIN
      wtt_demo.gif

+ 52
- 8
README.md

@ -1,25 +1,69 @@
# wtt # wtt
Work Time Tracker - console time tracking app Work Time Tracker - console time tracking app
Add wtt to the path:
```
export PATH="$PATH:/home/user/path/wtt"
```
### Use ### Use
Create new project
- Create new project
```
wtt new ProjectName
``` ```
./wtt new ProjectName
- Abreviation:
```
wtt n ProjectName
``` ```
- List projects
```
wtt list
```
- Abreviation:
```
wtt ls
```
Start working on a project
- Also can list with more details using:
``` ```
./wtt start ProjectName
wtt ls -a
``` ```
Stop working on the current project
- Start working on a project
```
wtt start ProjectName
``` ```
./wtt stop
- Abreviation:
```
wtt s ProjectName
``` ```
List projects
- Stop working on the current project
```
wtt stop
``` ```
./wtt list
- Delete project
``` ```
wtt rm ProjectName
```
- Show current working
```
wtt current
```
- Abreviation:
```
wtt c
```
- Help:
```
wtt help
```
- Abreviation:
```
wtt h
```
![wtt](https://raw.githubusercontent.com/arnaucode/wtt/master/wtt_demo.gif "wtt")

+ 47
- 10
main.go

@ -25,7 +25,7 @@ func main() {
//get the command line parameters //get the command line parameters
if len(os.Args) > 1 { if len(os.Args) > 1 {
switch os.Args[1] { switch os.Args[1] {
case "new":
case "new", "n":
//create project os.Args[2] //create project os.Args[2]
if len(os.Args) > 2 { if len(os.Args) > 2 {
projectName := os.Args[2] projectName := os.Args[2]
@ -39,11 +39,18 @@ func main() {
color.Red("No project name specified") color.Red("No project name specified")
} }
break break
case "list":
//list projects
listProjects()
case "list", "ls":
if len(os.Args) > 2 {
param := os.Args[2]
if param == "-a" {
listProjectsDetails()
}
} else {
//list projects
listProjects()
}
break break
case "start":
case "start", "s":
//check if already there is any project started //check if already there is any project started
if work.CurrentProjectName != "" { if work.CurrentProjectName != "" {
color.Red("Can not start project, already project " + work.CurrentProjectName + " running") color.Red("Can not start project, already project " + work.CurrentProjectName + " running")
@ -63,6 +70,8 @@ func main() {
work.CurrentProjectName = projectName work.CurrentProjectName = projectName
saveWork() saveWork()
fmt.Println("starting to work in project " + work.Projects[i].Name) fmt.Println("starting to work in project " + work.Projects[i].Name)
} else {
color.Red("No project name to start selected")
} }
break break
case "stop": case "stop":
@ -80,18 +89,46 @@ func main() {
work.Projects[i].Streaks[j].Duration = time.Now().Sub(work.Projects[i].Streaks[j].Start) work.Projects[i].Streaks[j].Duration = time.Now().Sub(work.Projects[i].Streaks[j].Start)
work.CurrentProjectName = "" work.CurrentProjectName = ""
saveWork() saveWork()
fmt.Print("Worked ")
fmt.Print(work.Projects[i].Streaks[j].Duration)
fmt.Println(" in the project " + work.Projects[i].Name)
color.Green("Worked " + work.Projects[i].Streaks[j].Duration.String() + " in the project " + work.Projects[i].Name)
break
case "rm":
if len(os.Args) > 2 {
projectName := os.Args[2]
if work.CurrentProjectName == projectName {
work.CurrentProjectName = ""
}
deleteProject(projectName)
saveWork()
color.Yellow("Project " + projectName + " deleted")
} else {
color.Red("no project name specified")
}
//stop project os.Args[2]
break break
case "current", "c":
if work.CurrentProjectName != "" {
fmt.Print("Current working project: ")
color.Blue(work.CurrentProjectName)
} else {
fmt.Println("No current working project.")
}
case "help", "h":
fmt.Println("./wtt new {projectname}")
fmt.Println("./wtt ls")
fmt.Println("./wtt ls -a")
fmt.Println("./wtt start {projectname}")
fmt.Println("./wtt stop")
fmt.Println("./wtt rm")
fmt.Println("./wtt current")
fmt.Println("./wtt help")
default: default:
color.Red("no option selected")
color.Red("option not exists")
os.Exit(1) os.Exit(1)
} }
} else { } else {
color.Red("no option selected") color.Red("no option selected")
fmt.Println("Can run 'help' for commands information")
fmt.Println("./wtt help")
os.Exit(1) os.Exit(1)
} }
} }

+ 55
- 1
work.go

@ -75,7 +75,7 @@ func newProject(name string) error {
work.Projects = append(work.Projects, newProject) work.Projects = append(work.Projects, newProject)
return nil return nil
} }
func listProjects() {
func listProjectsDetails() {
fmt.Println("") fmt.Println("")
fmt.Println("") fmt.Println("")
fmt.Println("Listing projects") fmt.Println("Listing projects")
@ -94,5 +94,59 @@ func listProjects() {
fmt.Println(streak.Duration) fmt.Println(streak.Duration)
} }
fmt.Println("") fmt.Println("")
showHoursByDays(project.Name)
fmt.Println("")
}
if work.CurrentProjectName != "" {
fmt.Print("Current working project: ")
color.Blue(work.CurrentProjectName)
} }
} }
func listProjects() {
fmt.Println("")
fmt.Println("")
fmt.Println("Listing projects")
fmt.Println("")
for k, project := range work.Projects {
fmt.Println("project " + strconv.Itoa(k))
fmt.Print("name: ")
color.Blue(project.Name)
showHoursByDays(project.Name)
fmt.Println("")
}
if work.CurrentProjectName != "" {
fmt.Print("Current working project: ")
color.Blue(work.CurrentProjectName)
}
}
func deleteProject(name string) {
i := getProjectIByName(name)
if i < 0 {
color.Red("Project name: " + name + ", no exists")
return
}
work.Projects = append(work.Projects[:i], work.Projects[i+1:]...)
}
func showHoursByDays(name string) {
timeFormat := "Mon, 01/02/06"
i := getProjectIByName(name)
if i < 0 {
color.Red("Project name: " + name + ", no exists")
return
}
p := work.Projects[i]
days := make(map[string]time.Duration)
for _, streak := range p.Streaks {
days[streak.Start.Format(timeFormat)] = addDurations(days[streak.Start.Format(timeFormat)], streak.Duration)
}
for day, hours := range days {
fmt.Print(" Day: " + day)
fmt.Print(", total time: ")
fmt.Println(hours)
}
}
func addDurations(d1 time.Duration, d2 time.Duration) time.Duration {
s := d1.Seconds() + d2.Seconds()
r := time.Duration(s) * time.Second
return r
}

BIN
wtt


BIN
wtt_demo.gif

Before After
Width: 592  |  Height: 400  |  Size: 1.7 MiB

Loading…
Cancel
Save