示例#1
0
func convertValues(store store.Store, project data.ProjectName, values [][]string) error {
	for _, value := range values {
		if len(value) < 2 {
			return errgo.New("value length must be at least 2")
		}

		timestamp, err := time.Parse(time.RFC3339Nano, value[0])
		if err != nil {
			return errgo.Notef(err, "can not parse timestamp of value")
		}

		log.Info("Timestamp: ", timestamp)

		switch value[1] {
		case "note":
			log.Debug("Saving note")
			note := data.Note{
				Value:     value[2],
				TimeStamp: timestamp,
			}

			err := store.AddEntry(project, note)
			if err != nil {
				return errgo.Notef(err, "can not save note to store")
			}

		case "todo":
			log.Debug("Saving todo")
			done, err := strconv.ParseBool(value[3])
			if err != nil {
				return errgo.Notef(err, "can not parse bool from value")
			}

			todo := data.Todo{
				Value:     value[2],
				TimeStamp: timestamp,
				Active:    !done,
			}

			err = store.AddEntry(project, todo)
			if err != nil {
				return errgo.Notef(err, "can not save note to store")
			}
		default:
			return errgo.New("do not know what to do with this type of value: " + value[1])
		}
	}

	return nil
}
示例#2
0
// ProjectNamesFromArgs will return all projects or all projects with
// subprojects if the length of the args is not 0.
func ProjectNamesFromArgs(store store.Store, args []string, showarchive bool) (data.Projects, error) {
	projects, err := store.ListProjects(showarchive)
	if err != nil {
		return data.Projects{}, errgo.Notef(err, "can not get list of projects")
	}

	log.Debug("Args: ", args)

	out := data.NewProjects()
	if len(args) == 0 {
		out = projects
	} else {
		for _, arg := range args {
			name, err := data.ParseProjectName(arg)
			if err != nil {
				return data.Projects{}, errgo.Notef(err, "can not parse project name")
			}

			items := projects.List(data.Project{Name: name})
			for _, item := range items {
				out.Add(item)
			}
		}
	}

	return out, nil
}