Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for adding metadata/attachments #614

Merged
merged 1 commit into from
Sep 28, 2022

Conversation

wkalt
Copy link
Contributor

@wkalt wkalt commented Sep 27, 2022

Add support for adding metadata/attachments

Adds support for adding and getting metadata and attachments from an
existing mcap file. To add an attachment to a file,

mcap add attachment demo.mcap -f Makefile

To get an attachment out of the file,

mcap get attachment demo.mcap -n Makefile -o attachment.txt

To add metadata to a file,

 mcap add metadata demo.mcap -k foo=bar -k bar=baz -n "my metadata"

To get metadata out of the file,

 mcap get metadata demo.mcap -n "my metadata"
 {
   "bar": "baz",
   "foo": "bar"
 }

Also fixes a bug in the list attachments subcommand. Previously this was
listing chunks.

Fixes: #434
Fixes: #372

@wkalt
Copy link
Contributor Author

wkalt commented Sep 27, 2022

todo:

  • spellcheck
  • ensure required flags are marked required
  • docstring on RewriteMCAP explaining future plans

go/cli/mcap/cmd/metadata.go Outdated Show resolved Hide resolved
die("Unexpected number of args")
}
filename := args[0]
err := utils.WithReader(ctx, filename, func(_ bool, rs io.ReadSeeker) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, the run commands in this patch are too heavy. It would be easier to test if these dispatched to standalone functions.

@wkalt wkalt force-pushed the wyatt/cli/add-metadata-attachment branch from 99c5027 to 870e338 Compare September 27, 2022 17:11
@wkalt wkalt force-pushed the wyatt/cli/add-metadata-attachment branch from 870e338 to e393a96 Compare September 27, 2022 17:22
@@ -111,10 +115,152 @@ func FormatTable(w io.Writer, rows [][]string) {
tw.Render()
}

func inferWriterOptions(info *mcap.Info) *mcap.WriterOptions {
// assume if there are no chunk indexes, the file is not chunked
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this assumption fail on an unindexed file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the file is chunked but not indexed, yeah it'll fail. I think though the only way to guard against that would be to scan the entire file to see if a chunk is present. I'm not sure that's worth it, but it's something we could do.

This is where it would be handy to have the writer options in the header.

@wkalt wkalt force-pushed the wyatt/cli/add-metadata-attachment branch from 52a1b5a to d49a81d Compare September 28, 2022 02:59
Adds support for adding and getting metadata and attachments from an
existing mcap file. To add an attachment to a file,

    mcap add attachment demo.mcap -f Makefile

To get an attachment out of the file,

    mcap get attachment demo.mcap -n Makefile -o attachment.txt

To add metadata to a file,

    mcap add metadata demo.mcap -k foo=bar -k bar=baz -n "my metadata"

To get metadata out of the file,

    mcap get metadata demo.mcap -n "my metadata"
    {
      "bar": "baz",
      "foo": "bar"
    }

Also fixes a bug in the list attachments subcommand. Previously this was
listing chunks.
@wkalt wkalt force-pushed the wyatt/cli/add-metadata-attachment branch from d49a81d to 1f66244 Compare September 28, 2022 03:00
@wkalt wkalt merged commit 0a2aba9 into main Sep 28, 2022
@wkalt wkalt deleted the wyatt/cli/add-metadata-attachment branch September 28, 2022 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

CLI: support attachments [mcap cli] Add metadata to an existing mcap file
2 participants