allow arbitrary strings after weight value in 'log' command

This commit is contained in:
gutmet 2025-01-12 22:21:54 +01:00
parent 9dff015945
commit 7098fb067e

View File

@ -72,7 +72,7 @@ func log(args []string) error {
if !isInitialized() {
return errNotInitialized()
}
if len(args) != 1 {
if len(args) < 1 {
return errors.New("log: Please provide weight as argument (floating point number)")
}
weight, err := strconv.ParseFloat(args[0], 64)
@ -80,10 +80,12 @@ func log(args []string) error {
return errors.New("log: " + err.Error())
}
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 {
return err
}
fmt.Print(newline)
return show(showFlags{})
}