2022-04-14 10:49:56 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
2022-04-17 12:30:33 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/meta"
|
2022-04-14 10:49:56 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/report"
|
|
|
|
)
|
|
|
|
|
2023-01-25 11:41:39 +01:00
|
|
|
// ShowMetadataCommand configures the command name, flags, and action.
|
|
|
|
var ShowMetadataCommand = cli.Command{
|
|
|
|
Name: "metadata",
|
|
|
|
Usage: "Displays supported metadata tags and standards",
|
2022-04-17 12:30:33 +02:00
|
|
|
Flags: append(report.CliFlags, cli.BoolFlag{
|
|
|
|
Name: "short, s",
|
|
|
|
Usage: "hide links to documentation",
|
|
|
|
}),
|
2023-01-25 11:41:39 +01:00
|
|
|
Action: showMetadataAction,
|
2022-04-14 10:49:56 +02:00
|
|
|
}
|
|
|
|
|
2023-01-25 11:41:39 +01:00
|
|
|
// showMetadataAction reports supported Exif and XMP metadata tags.
|
|
|
|
func showMetadataAction(ctx *cli.Context) error {
|
2022-04-14 10:49:56 +02:00
|
|
|
rows, cols := meta.Report(&meta.Data{})
|
|
|
|
|
2022-04-14 12:30:47 +02:00
|
|
|
// Sort rows by type data type and name.
|
2022-04-14 10:49:56 +02:00
|
|
|
sort.Slice(rows, func(i, j int) bool {
|
|
|
|
if rows[i][1] == rows[j][1] {
|
|
|
|
return rows[i][0] < rows[j][0]
|
|
|
|
} else {
|
|
|
|
return rows[i][1] < rows[j][1]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-04-17 12:30:33 +02:00
|
|
|
// Output overview of supported metadata tags.
|
|
|
|
format := report.CliFormat(ctx)
|
2022-10-10 16:34:07 +02:00
|
|
|
result, err := report.RenderFormat(rows, cols, format)
|
2022-04-14 10:49:56 +02:00
|
|
|
|
2022-04-17 12:30:33 +02:00
|
|
|
fmt.Println(result)
|
|
|
|
|
|
|
|
if err != nil || ctx.Bool("short") || format == report.TSV {
|
|
|
|
return err
|
2022-04-16 19:52:53 +02:00
|
|
|
}
|
2022-04-14 12:18:05 +02:00
|
|
|
|
2022-04-17 12:30:33 +02:00
|
|
|
// Documentation links for those who want to delve deeper.
|
2022-10-10 16:34:07 +02:00
|
|
|
result, err = report.RenderFormat(meta.Docs, []string{"Namespace", "Documentation"}, format)
|
2022-04-17 12:30:33 +02:00
|
|
|
|
|
|
|
fmt.Printf("## Metadata Tags by Namespace ##\n\n")
|
|
|
|
fmt.Println(result)
|
|
|
|
|
|
|
|
return err
|
2022-04-14 10:49:56 +02:00
|
|
|
}
|