From a8f36b2812daacfc6b0f4d5c77e9a0452cfafb3c Mon Sep 17 00:00:00 2001 From: Kasey Date: Thu, 21 Mar 2019 17:22:50 -0400 Subject: [PATCH] feat(save): add `no-render` option to `qri save` command This commit also plumbs the flag down to base! Adjusting tests as needed. --- actions/actions_test.go | 6 +++--- actions/dataset.go | 4 ++-- actions/dataset_test.go | 16 ++++++++-------- base/base_test.go | 6 +++--- base/dataset.go | 4 ++-- base/dataset_test.go | 12 ++++++------ cmd/save.go | 3 +++ lib/datasets.go | 4 +++- lib/lib_test.go | 4 ++-- p2p/log_diff_test.go | 4 ++-- p2p/log_test.go | 2 +- repo/test/test_repo.go | 2 +- 12 files changed, 36 insertions(+), 31 deletions(-) diff --git a/actions/actions_test.go b/actions/actions_test.go index b28ad25ae..fc8d395fb 100644 --- a/actions/actions_test.go +++ b/actions/actions_test.go @@ -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()) } @@ -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()) } @@ -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()) } diff --git a/actions/dataset.go b/actions/dataset.go index c41231dd5..44591bd82 100644 --- a/actions/dataset.go +++ b/actions/dataset.go @@ -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 @@ -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 diff --git a/actions/dataset_test.go b/actions/dataset_test.go index d55618035..52e445a2a 100644 --- a/actions/dataset_test.go +++ b/actions/dataset_test.go @@ -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) } @@ -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()) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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()) diff --git a/base/base_test.go b/base/base_test.go index 55dd52d74..e1ca9da93 100644 --- a/base/base_test.go +++ b/base/base_test.go @@ -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()) } @@ -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()) } @@ -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()) } diff --git a/base/dataset.go b/base/dataset.go index 7889d17d0..667f051e0 100644 --- a/base/dataset.go +++ b/base/dataset.go @@ -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 @@ -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 != "/" { diff --git a/base/dataset_test.go b/base/dataset_test.go index 6797022a3..cf8f485d0 100644 --- a/base/dataset_test.go +++ b/base/dataset_test.go @@ -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()) } @@ -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()) } @@ -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) } } @@ -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 diff --git a/cmd/save.go b/cmd/save.go index a883fb7ab..e3c680d30 100644 --- a/cmd/save.go +++ b/cmd/save.go @@ -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 } @@ -89,6 +90,7 @@ type SaveOptions struct { DryRun bool KeepFormat bool Force bool + NoRender bool Secrets []string DatasetRequests *lib.DatasetRequests @@ -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 { diff --git a/lib/datasets.go b/lib/datasets.go index 07dfa164a..4dbf98711 100644 --- a/lib/datasets.go +++ b/lib/datasets.go @@ -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 @@ -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 diff --git a/lib/lib_test.go b/lib/lib_test.go index 7342a100e..9233eab5c 100644 --- a/lib/lib_test.go +++ b/lib/lib_test.go @@ -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()) } @@ -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()) } diff --git a/p2p/log_diff_test.go b/p2p/log_diff_test.go index 29273bb06..5a1206952 100644 --- a/p2p/log_diff_test.go +++ b/p2p/log_diff_test.go @@ -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) } @@ -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) } diff --git a/p2p/log_test.go b/p2p/log_test.go index d96fb1833..3e5f759d0 100644 --- a/p2p/log_test.go +++ b/p2p/log_test.go @@ -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) } diff --git a/repo/test/test_repo.go b/repo/test/test_repo.go index ce1f1ed70..9377f5213 100644 --- a/repo/test/test_repo.go +++ b/repo/test/test_repo.go @@ -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 }