-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(export): Overhaul export command
Many changes to the export command to get it working more closely in line with the recent rfc https://github.com/qri-io/rfcs/blob/master/text/0021-export_behavior.md. Changes include: * Export as a single file yaml * Respect `use` when exporting * Derive the filename when -o flag isn't used, using the repo name and timestamp * Derive the format if -o is used, by looking at the file extension * Calculate absolute path for where export should write, without uglyfying console output * Introduce new base.ReadEntries utility for turning EntryReader into body * Switch default export format to single file json Some things that are broken now, to be fixed later: * --zipped is broken for now * Raw block "native" export format * Needs tests
- Loading branch information
Showing
6 changed files
with
212 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package base | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/qri-io/dataset/dsio" | ||
) | ||
|
||
// ReadEntries reads entries and returns them as a native go array or map | ||
func ReadEntries(reader dsio.EntryReader, all bool, limit int, offset int) (interface{}, error) { | ||
obj := make(map[string]interface{}) | ||
array := make([]interface{}, 0) | ||
numRead := 0 | ||
|
||
tlt, err := dsio.GetTopLevelType(reader.Structure()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for i := 0;; i++ { | ||
val, err := reader.ReadEntry() | ||
if err != nil { | ||
if err.Error() == "EOF" { | ||
break | ||
} | ||
return nil, err | ||
} | ||
if !all && i < offset { | ||
continue | ||
} | ||
|
||
if tlt == "object" { | ||
obj[val.Key] = val.Value | ||
} else { | ||
array = append(array, val.Value) | ||
} | ||
|
||
numRead++ | ||
if !all && numRead == limit { | ||
break | ||
} | ||
} | ||
|
||
if tlt == "object" { | ||
return obj, nil | ||
} | ||
return array, nil | ||
} | ||
|
||
// ReadEntriesToArray reads entries and returns them as a native go array | ||
func ReadEntriesToArray(reader dsio.EntryReader, all bool, limit int, offset int) ([]interface{}, error) { | ||
entries, err := ReadEntries(reader, all, limit, offset) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
array, ok := entries.([]interface{}) | ||
if !ok { | ||
return nil, fmt.Errorf("cannot convert top-level to array") | ||
} | ||
|
||
return array, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.