allow arbitrary strings after weight value in 'log' command
This commit is contained in:
parent
9dff015945
commit
7098fb067e
6
hdiet.go
6
hdiet.go
|
@ -72,7 +72,7 @@ func log(args []string) error {
|
||||||
if !isInitialized() {
|
if !isInitialized() {
|
||||||
return errNotInitialized()
|
return errNotInitialized()
|
||||||
}
|
}
|
||||||
if len(args) != 1 {
|
if len(args) < 1 {
|
||||||
return errors.New("log: Please provide weight as argument (floating point number)")
|
return errors.New("log: Please provide weight as argument (floating point number)")
|
||||||
}
|
}
|
||||||
weight, err := strconv.ParseFloat(args[0], 64)
|
weight, err := strconv.ParseFloat(args[0], 64)
|
||||||
|
@ -80,10 +80,12 @@ func log(args []string) error {
|
||||||
return errors.New("log: " + err.Error())
|
return errors.New("log: " + err.Error())
|
||||||
}
|
}
|
||||||
date := time.Now().Format(dateLayout)
|
date := time.Now().Format(dateLayout)
|
||||||
err = goutil.AppendToFile(logfile, fmt.Sprintf("%s\t%.1f\n", date, weight))
|
newline := fmt.Sprintf("%s\t%.1f\t%s\n", date, weight, strings.Join(args[1:], " "))
|
||||||
|
err = goutil.AppendToFile(logfile, newline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
fmt.Print(newline)
|
||||||
return show(showFlags{})
|
return show(showFlags{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user