earthstar-project / earthstar-cli

A complete Earthstar toolbox in the console.
GNU Lesser General Public License v3.0
12 stars 1 forks source link

Import/export a single earthstar document to a file #2

Open cinnamon-bun opened 4 years ago

cinnamon-bun commented 4 years ago

Add some commands to make it easier to import/export single documents to files, either as JSON (including the document metadata) or just as the document content.

// new commands
earthstar document
earthstar content [--binary]

// new flags to existing command
earthstar set --fromFile <filename> [--binary]

Usage

// print out a whole document as JSON
earthstar document <dbFilename> <path>

// prints out just document.content
earthstar content <dbFilename> <path>

// redirect it to a file, to export the data out of earthstar
earthstar content <dbFilename> <path> > myfile

// read data from a file to use as the document's content
earthstar set <dbFilename> <authorFile> <path> --fromFile <filename>

// new option --binary means treat the file as binary instead of utf-8
// which means it needs to be encoded/decoded to base64 for storage in Earthstar
earthstar content <dbFilename> <path> --binary
earthstar set <dbFilename> <authorFile> <path> --fromFile <filename> --binary

Or maybe instead of --fromFile, it could try to read from stdin so you could do earthstar set db.sqlite author.json /path < myfile