Ejemplo n.º 1
0
func GetObject(c *cli.Context) {
	colors.Allow(c)

	objectId := helper.ValidId(c.Args().First())

	object, err := data.GetObject(objectId)
	helper.ErrExit(err != nil, fmt.Sprintf("Invalid object ID %s!\n", objectId))

	attributes := make(map[string][]string)
	for _, attribute := range object.Attributes {
		attributes[attribute.Name] = append(attributes[attribute.Name], attribute.Value)
	}

	keys := make([]string, 0, len(attributes))
	for k := range attributes {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	fmt.Printf("%s\n\n", colors.Bold(object.Title))
	fmt.Printf("%s\n\t%s\n", colors.Header("Created"), object.CreateDate.Format(time.RFC1123))

	if _, exists := attributes["content"]; exists {
		fmt.Printf("\n%s\n\t%s\n", colors.Header("Content"), strings.Join(attributes["content"], ", "))
		delete(attributes, "content")
	}

	if len(attributes) > 0 {
		fmt.Printf("\n%s\n", colors.Header("Attributes"))

		for k := range keys {
			sort.Strings(attributes[keys[k]])

			fmt.Printf("\t%s: %s\n", colors.Bold(keys[k]), strings.Join(attributes[keys[k]], ", "))
		}
	}

	if len(object.Attachments) > 0 {
		data.ClearCache()
		defer data.FlushCache()

		fmt.Printf("\n%s\n", colors.Header("Attachments"))

		for index, attachment := range object.Attachments {
			fmt.Printf("\t(%s) %s: %s (%s)\n", colors.ShortId(index+1), colors.ObjectId(attachment.Id.Hex()), attachment.Filename, attachment.UploadDate.Format(time.RFC1123))
			data.SetCache(strconv.Itoa(index+1), attachment.Id.Hex())
		}
	}
}
Ejemplo n.º 2
0
func GetAttachmentInfo(c *cli.Context) {
	objectId := helper.ValidId(c.Args().First())

	attachment, err := data.GetAttachment(objectId)
	helper.ErrPanic(err)

	metadata := make(map[string]string)
	for _, attribute := range attachment.MetaData {
		metadata[attribute.Name] = attribute.Value
	}

	keys := make([]string, 0, len(metadata))
	for k := range metadata {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	fmt.Printf("%s\n\n", colors.Bold(attachment.Filename))
	fmt.Printf("%s\n\t%s\n", colors.Header("Uploaded"), attachment.UploadDate.Format(time.RFC1123))

	for _, name := range keys {
		fmt.Printf("%s\n\t%v\n", colors.Header(name), metadata[name])
	}
}