diff --git a/README.md b/README.md index 07bd957..e39148a 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,69 @@ # wtt Work Time Tracker - console time tracking app +Add wtt to the path: +``` +export PATH="$PATH:/home/user/path/wtt" +``` ### 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") diff --git a/main.go b/main.go index 8e43d9f..1dced96 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ func main() { //get the command line parameters if len(os.Args) > 1 { switch os.Args[1] { - case "new": + case "new", "n": //create project os.Args[2] if len(os.Args) > 2 { projectName := os.Args[2] @@ -39,11 +39,18 @@ func main() { color.Red("No project name specified") } 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 - case "start": + case "start", "s": //check if already there is any project started if work.CurrentProjectName != "" { color.Red("Can not start project, already project " + work.CurrentProjectName + " running") @@ -63,6 +70,8 @@ func main() { work.CurrentProjectName = projectName saveWork() fmt.Println("starting to work in project " + work.Projects[i].Name) + } else { + color.Red("No project name to start selected") } break case "stop": @@ -80,18 +89,46 @@ func main() { work.Projects[i].Streaks[j].Duration = time.Now().Sub(work.Projects[i].Streaks[j].Start) work.CurrentProjectName = "" 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 + 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: - color.Red("no option selected") + color.Red("option not exists") os.Exit(1) } } else { color.Red("no option selected") + fmt.Println("Can run 'help' for commands information") + fmt.Println("./wtt help") os.Exit(1) } } diff --git a/work.go b/work.go index da3a7f0..f6c4d41 100644 --- a/work.go +++ b/work.go @@ -75,7 +75,7 @@ func newProject(name string) error { work.Projects = append(work.Projects, newProject) return nil } -func listProjects() { +func listProjectsDetails() { fmt.Println("") fmt.Println("") fmt.Println("Listing projects") @@ -94,5 +94,59 @@ func listProjects() { fmt.Println(streak.Duration) } 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 +} diff --git a/wtt b/wtt index dcc10ad..0044993 100755 Binary files a/wtt and b/wtt differ diff --git a/wtt_demo.gif b/wtt_demo.gif new file mode 100644 index 0000000..c40ec7f Binary files /dev/null and b/wtt_demo.gif differ