Skip to content

Commit

Permalink
feat(save): add no-render option to qri save command
Browse files Browse the repository at this point in the history
This commit also plumbs the flag down to base! Adjusting tests as needed.
  • Loading branch information
ramfox committed Mar 21, 2019
1 parent 90719a8 commit a8f36b2
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 31 deletions.
6 changes: 3 additions & 3 deletions actions/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func addCitiesDataset(t *testing.T, node *p2p.QriNode) repo.DatasetRef {
t.Fatal(err.Error())
}

ref, err := SaveDataset(node, tc.Input, nil, nil, false, true, false, false)
ref, err := SaveDataset(node, tc.Input, nil, nil, false, true, false, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -129,7 +129,7 @@ func addFlourinatedCompoundsDataset(t *testing.T, node *p2p.QriNode) repo.Datase
t.Fatal(err.Error())
}

ref, err := SaveDataset(node, tc.Input, nil, nil, false, true, false, false)
ref, err := SaveDataset(node, tc.Input, nil, nil, false, true, false, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -145,7 +145,7 @@ func addNowTransformDataset(t *testing.T, node *p2p.QriNode) repo.DatasetRef {
// this was put here to satisfy qri-io/qri/actions.TestUpdateDatasetLocal
tc.Input.Peername = "peer"

ref, err := SaveDataset(node, tc.Input, nil, nil, false, true, false, false)
ref, err := SaveDataset(node, tc.Input, nil, nil, false, true, false, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions actions/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// SaveDataset initializes a dataset from a dataset pointer and data file
func SaveDataset(node *p2p.QriNode, changes *dataset.Dataset, secrets map[string]string, scriptOut io.Writer, dryRun, pin, convertFormatToPrev, force bool) (ref repo.DatasetRef, err error) {
func SaveDataset(node *p2p.QriNode, changes *dataset.Dataset, secrets map[string]string, scriptOut io.Writer, dryRun, pin, convertFormatToPrev, force, shouldRender bool) (ref repo.DatasetRef, err error) {
var (
prevPath string
pro *profile.Profile
Expand Down Expand Up @@ -86,7 +86,7 @@ func SaveDataset(node *p2p.QriNode, changes *dataset.Dataset, secrets map[string
// let's make history, if it exists:
changes.PreviousPath = prevPath

return base.CreateDataset(r, node.LocalStreams, changes, prev, dryRun, pin, force)
return base.CreateDataset(r, node.LocalStreams, changes, prev, dryRun, pin, force, shouldRender)
}

// UpdateRemoteDataset brings a reference to the latest version, syncing to the
Expand Down
16 changes: 8 additions & 8 deletions actions/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestUpdateRemoteDataset(t *testing.T) {
ds.SetBodyFile(qfs.NewMemfileBytes("body.json", []byte("[]")))

// run a local update to advance history
now0, err := SaveDataset(peers[0], ds, nil, nil, false, true, false, false)
now0, err := SaveDataset(peers[0], ds, nil, nil, false, true, false, false, true)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestSaveDataset(t *testing.T) {
}
ds.SetBodyFile(qfs.NewMemfileBytes("body.json", []byte("[]")))

ref, err := SaveDataset(n, ds, nil, nil, true, false, false, false)
ref, err := SaveDataset(n, ds, nil, nil, true, false, false, false, true)
if err != nil {
t.Errorf("dry run error: %s", err.Error())
}
Expand All @@ -143,7 +143,7 @@ func TestSaveDataset(t *testing.T) {
ds.SetBodyFile(qfs.NewMemfileBytes("body.json", []byte("[]")))

// test save
ref, err = SaveDataset(n, ds, nil, nil, false, true, false, false)
ref, err = SaveDataset(n, ds, nil, nil, false, true, false, false, true)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestSaveDataset(t *testing.T) {
ds.Transform.OpenScriptFile(nil)

// dryrun should work
ref, err = SaveDataset(n, ds, secrets, nil, true, false, false, false)
ref, err = SaveDataset(n, ds, secrets, nil, true, false, false, false, true)
if err != nil {
t.Fatal(err)
}
Expand All @@ -200,7 +200,7 @@ func TestSaveDataset(t *testing.T) {
ds.Transform.OpenScriptFile(nil)

// test save with transform
ref, err = SaveDataset(n, ds, secrets, nil, false, true, false, false)
ref, err = SaveDataset(n, ds, secrets, nil, false, true, false, false, true)
if err != nil {
t.Fatal(err)
}
Expand All @@ -219,7 +219,7 @@ func TestSaveDataset(t *testing.T) {
},
}

ref, err = SaveDataset(n, ds, nil, nil, false, true, false, false)
ref, err = SaveDataset(n, ds, nil, nil, false, true, false, false, true)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestSaveDataset(t *testing.T) {
t.Error(err)
}

ref, err = SaveDataset(n, ds, secrets, nil, false, true, false, false)
ref, err = SaveDataset(n, ds, secrets, nil, false, true, false, false, true)
if err != nil {
t.Error(err)
}
Expand All @@ -266,7 +266,7 @@ func TestSaveDatasetWithoutStructureOrBody(t *testing.T) {
},
}

_, err := SaveDataset(n, ds, nil, nil, false, false, false, false)
_, err := SaveDataset(n, ds, nil, nil, false, false, false, false, true)
expect := "creating a new dataset requires a structure or a body"
if err == nil || err.Error() != expect {
t.Errorf("expected error, but got %s", err.Error())
Expand Down
6 changes: 3 additions & 3 deletions base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func addCitiesDataset(t *testing.T, r repo.Repo) repo.DatasetRef {
t.Fatal(err.Error())
}

ref, err := CreateDataset(r, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false)
ref, err := CreateDataset(r, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func updateCitiesDataset(t *testing.T, r repo.Repo) repo.DatasetRef {
tc.Input.PreviousPath = ""
}()

ref, err = CreateDataset(r, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false)
ref, err = CreateDataset(r, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -107,7 +107,7 @@ func addFlourinatedCompoundsDataset(t *testing.T, r repo.Repo) repo.DatasetRef {
t.Fatal(err.Error())
}

ref, err := CreateDataset(r, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false)
ref, err := CreateDataset(r, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions base/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func ListDatasets(r repo.Repo, limit, offset int, RPC, publishedOnly, showVersio
// CreateDataset uses dsfs to add a dataset to a repo's store, updating all
// references within the repo if successful. CreateDataset is a lower-level
// component of github.com/qri-io/qri/actions.CreateDataset
func CreateDataset(r repo.Repo, streams ioes.IOStreams, ds, dsPrev *dataset.Dataset, dryRun, pin, force bool) (ref repo.DatasetRef, err error) {
func CreateDataset(r repo.Repo, streams ioes.IOStreams, ds, dsPrev *dataset.Dataset, dryRun, pin, force, shouldRender bool) (ref repo.DatasetRef, err error) {
var (
pro *profile.Profile
path string
Expand All @@ -143,7 +143,7 @@ func CreateDataset(r repo.Repo, streams ioes.IOStreams, ds, dsPrev *dataset.Data
return
}

if path, err = dsfs.CreateDataset(r.Store(), ds, dsPrev, r.PrivateKey(), pin, force); err != nil {
if path, err = dsfs.CreateDataset(r.Store(), ds, dsPrev, r.PrivateKey(), pin, force, shouldRender); err != nil {
return
}
if ds.PreviousPath != "" && ds.PreviousPath != "/" {
Expand Down
12 changes: 6 additions & 6 deletions base/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func TestCreateDataset(t *testing.T) {
}
ds.SetBodyFile(qfs.NewMemfileBytes("body.json", []byte("[]")))

if _, err := CreateDataset(r, streams, &dataset.Dataset{}, &dataset.Dataset{}, false, true, false); err == nil {
if _, err := CreateDataset(r, streams, &dataset.Dataset{}, &dataset.Dataset{}, false, true, false, true); err == nil {
t.Error("expected bad dataset to error")
}

ref, err := CreateDataset(r, streams, ds, &dataset.Dataset{}, false, true, false)
ref, err := CreateDataset(r, streams, ds, &dataset.Dataset{}, false, true, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -96,7 +96,7 @@ func TestCreateDataset(t *testing.T) {

prev := ref.Dataset

ref, err = CreateDataset(r, streams, ds, prev, false, true, false)
ref, err = CreateDataset(r, streams, ds, prev, false, true, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -112,12 +112,12 @@ func TestCreateDataset(t *testing.T) {
ds.SetBodyFile(qfs.NewMemfileBytes("body.json", []byte("[]")))
prev = ref.Dataset

if ref, err = CreateDataset(r, streams, ds, prev, false, true, false); err == nil {
if ref, err = CreateDataset(r, streams, ds, prev, false, true, false, true); err == nil {
t.Error("expected unchanged dataset with no force flag to error")
}

ds.SetBodyFile(qfs.NewMemfileBytes("body.json", []byte("[]")))
if ref, err = CreateDataset(r, streams, ds, prev, false, true, true); err != nil {
if ref, err = CreateDataset(r, streams, ds, prev, false, true, true, true); err != nil {
t.Errorf("unexpected force-save error: %s", err)
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestDatasetPinning(t *testing.T) {
return
}

ref2, err := CreateDataset(r, streams, tc.Input, nil, false, false, false)
ref2, err := CreateDataset(r, streams, tc.Input, nil, false, false, false, true)
if err != nil {
t.Error(err.Error())
return
Expand Down
3 changes: 3 additions & 0 deletions cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ commit message and title to the save.`,
cmd.Flags().BoolVar(&o.DryRun, "dry-run", false, "simulate saving a dataset")
cmd.Flags().BoolVar(&o.Force, "force", false, "force a new commit, even if no changes are detected")
cmd.Flags().BoolVarP(&o.KeepFormat, "keep-format", "k", false, "convert incoming data to stored data format")
cmd.Flags().BoolVarP(&o.NoRender, "no-render", "n", false, "don't store a rendered version of the the vizualization ")

return cmd
}
Expand All @@ -89,6 +90,7 @@ type SaveOptions struct {
DryRun bool
KeepFormat bool
Force bool
NoRender bool
Secrets []string

DatasetRequests *lib.DatasetRequests
Expand Down Expand Up @@ -150,6 +152,7 @@ func (o *SaveOptions) Run() (err error) {
ConvertFormatToPrev: o.KeepFormat,
Force: o.Force,
ReturnBody: o.DryRun,
ShouldRender: !o.NoRender,
}

if o.Secrets != nil {
Expand Down
4 changes: 3 additions & 1 deletion lib/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ type SaveParams struct {
Recall string
// force a new commit, even if no changes are detected
Force bool
// save a rendered version of the template along with the dataset
ShouldRender bool
// optional writer to have transform script record standard output to
// note: this won't work over RPC, only on local calls
ScriptOutput io.Writer
Expand Down Expand Up @@ -275,7 +277,7 @@ func (r *DatasetRequests) Save(p *SaveParams, res *repo.DatasetRef) (err error)
return
}

ref, err := actions.SaveDataset(r.node, ds, p.Secrets, p.ScriptOutput, p.DryRun, true, p.ConvertFormatToPrev, p.Force)
ref, err := actions.SaveDataset(r.node, ds, p.Secrets, p.ScriptOutput, p.DryRun, true, p.ConvertFormatToPrev, p.Force, p.ShouldRender)
if err != nil {
log.Debugf("create ds error: %s\n", err.Error())
return err
Expand Down
4 changes: 2 additions & 2 deletions lib/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func addCitiesDataset(t *testing.T, node *p2p.QriNode) repo.DatasetRef {
ds.Name = tc.Name
ds.BodyBytes = tc.Body

ref, err := actions.SaveDataset(node, ds, nil, nil, false, true, false, false)
ref, err := actions.SaveDataset(node, ds, nil, nil, false, true, false, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -95,7 +95,7 @@ func addNowTransformDataset(t *testing.T, node *p2p.QriNode) repo.DatasetRef {
ds.Name = tc.Name
ds.Transform.ScriptPath = "testdata/now_tf/transform.star"

ref, err := actions.SaveDataset(node, ds, nil, nil, false, true, false, false)
ref, err := actions.SaveDataset(node, ds, nil, nil, false, true, false, false, true)
if err != nil {
t.Fatal(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/log_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestRequestLogDiff(t *testing.T) {
}

// add a dataset to peer 4
ref, err := base.CreateDataset(peers[4].Repo, streams, tc.Input, nil, false, true, false)
ref, err := base.CreateDataset(peers[4].Repo, streams, tc.Input, nil, false, true, false, true)
if err != nil {
t.Fatal(err)
}
Expand All @@ -50,7 +50,7 @@ func TestRequestLogDiff(t *testing.T) {
update.Name = tc.Name

// add an update on peer 4
ref2, err := base.CreateDataset(peers[4].Repo, streams, update, tc.Input, false, true, false)
ref2, err := base.CreateDataset(peers[4].Repo, streams, update, tc.Input, false, true, false, true)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestRequestDatasetLog(t *testing.T) {
}

// add a dataset to tim
ref, err := base.CreateDataset(peers[4].Repo, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false)
ref, err := base.CreateDataset(peers[4].Repo, ioes.NewDiscardIOStreams(), tc.Input, nil, false, true, false, true)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion repo/test/test_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func createDataset(r repo.Repo, tc dstest.TestCase) (err error) {
ds.Commit.Author = &dataset.User{ID: pro.ID.String()}
}

_, err = base.CreateDataset(r, ioes.NewDiscardIOStreams(), ds, nil, false, true, false)
_, err = base.CreateDataset(r, ioes.NewDiscardIOStreams(), ds, nil, false, true, false, true)
return
}

Expand Down

0 comments on commit a8f36b2

Please sign in to comment.