diff options
| author | Teddy Wing | 2017-06-03 17:35:24 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-03 17:35:24 +0200 | 
| commit | 80c8fa343a3d98c0601545ef9b3df743c6b6b901 (patch) | |
| tree | 3f794accf3624808462c8af2f0f7f1c04d05714e | |
| parent | 47ec5ffeea72fff2019636be2c97ee36fcd176a6 (diff) | |
| parent | 81791bbf4291e28691ed2cfaaad357613c915174 (diff) | |
| download | timetasker-80c8fa343a3d98c0601545ef9b3df743c6b6b901.tar.bz2 | |
Merge branch 'command-line-arguments' into timetasker-daily
| -rw-r--r-- | main.go | 63 | ||||
| -rw-r--r-- | timetask/http.go | 5 | ||||
| -rw-r--r-- | timetask/time_entry.go | 4 | 
3 files changed, 62 insertions, 10 deletions
| @@ -2,14 +2,19 @@ package main  import (  	"io/ioutil" +	"fmt"  	"log" +	"os"  	"time"  	"github.com/teddywing/timetasker/timetask"  	"github.com/BurntSushi/toml" +	"gopkg.in/alecthomas/kingpin.v2"  ) +var VERSION string = "0.1.0" +  type Config struct {  	Auth struct {  		Username    string @@ -22,8 +27,59 @@ type Config struct {  var config Config  func main() { +	var err error +  	loadConfig() +	// Parse command line arguments +	project_alias := kingpin.Flag( +		"project", +		"Project alias defined in config.toml.", +	). +		Short('p'). +		Required(). +		String() +	time_spent := kingpin.Flag("time", "Time spent working on project."). +		Short('t'). +		Default("7"). +		Float() +	date_str := kingpin.Flag("date", "Date when work was done (e.g. 2017-01-31)"). +		Short('d'). +		String() +	description := kingpin.Flag("description", "Description of work."). +		Short('m'). +		String() +	kingpin.Version(VERSION) +	kingpin.Parse() + +	// Submit time entry +	project, ok := config.Projects[*project_alias] +	if !ok { +		fmt.Printf("Project '%s' not found\n", *project_alias) +		os.Exit(1) +	} + +	var date time.Time + +	// If the date argument isn't sent, default to today +	if *date_str == "" { +		date = time.Now() +	} else { +		date, err = time.Parse("2006-01-02", *date_str) +		if err != nil { +			fmt.Printf("Date '%s' could not be parsed. Example: -d 2017-01-31\n", *date_str) +			os.Exit(1) +		} +	} + +	time_entry := timetask.NewTimeEntry( +		config.Profile, +		project, +		date, +		*time_spent, +		*description, +	) +  	resp, client, err := timetask.Login(  		config.Auth.Username,  		config.Auth.PasswordCmd, @@ -37,13 +93,6 @@ func main() {  	body, err := ioutil.ReadAll(resp.Body)  	log.Println(string(body)) -	time_entry := timetask.NewTimeEntry( -		config.Profile, -		config.Projects["example"], -		time.Now(), -		7, -		"timetasker test", -	)  	resp, err = timetask.SubmitTimeEntry(*client, time_entry)  	if err != nil {  		log.Fatalln(err) diff --git a/timetask/http.go b/timetask/http.go index 6e73276..f236665 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -5,6 +5,7 @@ import (  	"net/http/cookiejar"  	"net/url"  	"strconv" +	"strings"  	"golang.org/x/net/publicsuffix"  ) @@ -97,9 +98,11 @@ func buildSubmissionParams(time_entry TimeEntry) url.Values {  		time_entry.Date.Format("02/01/06"), // day/month/year  	) +	time_str := strconv.FormatFloat(time_entry.Time, 'f', 2, 64) +	time_european_format := strings.Replace(time_str, ".", ",", 0)  	v.Set(  		"f_time0", -		strconv.Itoa(time_entry.Time), +		time_european_format,  	)  	var billable string diff --git a/timetask/time_entry.go b/timetask/time_entry.go index ff0ad1f..bb7a741 100644 --- a/timetask/time_entry.go +++ b/timetask/time_entry.go @@ -10,7 +10,7 @@ type TimeEntry struct {  	Task        int  	WorkType    int  	Date        time.Time -	Time        int +	Time        float64  	Billable    bool  	Description string  } @@ -19,7 +19,7 @@ func NewTimeEntry(  	profile Profile,  	project Project,  	date time.Time, -	time int, +	time float64,  	description string,  ) TimeEntry {  	return TimeEntry{ | 
