- commit
- 37f5d9959d152710ceacd2d100ba2a08a715fdcb
- parent
- c4c579cc1bb331655a021b90fb9794a508c0bca6
- author
- Dami <dami.etoile@gmail.com>
- kind
- fix risk score 1.6 of 3, Jev's estimate
| M | cmd/ | 16 | +++------------- |
| M | cmd/ | 7 | ++++--- |
| M | docs/ | 3 | ++- |
| M | internal/ | 17 | +++++++++++++++++ |
@@ -9,7 +9,6 @@ import (
99 1010 "github.com/FelineStateMachine/012/internal/headless"1111 "github.com/FelineStateMachine/012/internal/notebook"12- "github.com/FelineStateMachine/012/internal/sheet"1312 )1413 1514 // 012 get, set and recalc: workbook files read and changed without the@@ -57,22 +56,13 @@ func runGet(args []string, e env) error {
5756 if err := headless.Get(e.stdout, t, o); err != nil {5857 return err5958 }60- if !a.has("notebooks") && hasOutputs(t.Sheet) {61- fmt.Fprintln(e.stderr, "012: note: "+t.Sheet.Name()+" shows notebook outputs as the file kept them; --notebooks runs the cells again")59+ if missing := headless.MissingOutputs(t.Sheet); !a.has("notebooks") && len(missing) > 0 {60+ fmt.Fprintf(e.stderr, "012: note: %s shows no rows for %s, whose output the file doesn't hold; --notebooks runs the notebook\n",61+ t.Sheet.Name(), strings.Join(missing, ", "))6262 }6363 return failed.err()6464 }6565 66-// hasOutputs reports whether notebook cells' outputs were sent to s.67-func hasOutputs(s *sheet.Sheet) bool {68- for _, r := range s.Regions() {69- if r.Output {70- return true71- }72- }73- return false74-}75-7666 // runSet is 012 set: type entries into cells and save.7767 func runSet(args []string, e env) error {7868 a, err := parseArgs(args, nil, []string{"force", "help"})@@ -164,7 +164,7 @@ func TestNotebooksNeedTrust(t *testing.T) {
164164 path := notebookFile(t, "another computer")165165 166166 status(e, "get", path, "A2")167- if nu.ran != 0 || out.String() != "\n" || !strings.Contains(errOut.String(), "Sheet1 shows notebook outputs as the file kept them; --notebooks runs the cells again") {167+ if nu.ran != 0 || out.String() != "\n" || !strings.Contains(errOut.String(), "012: note: Sheet1 shows no rows for files, whose output the file doesn't hold; --notebooks runs the notebook\n") {168168 t.Errorf("without --notebooks: ran %d, %q %q", nu.ran, out, errOut)169169 }170170 if code, err := status(e, "get", path, "A2", "--notebooks"); code != 1 || nu.ran != 0 || !strings.Contains(err.Error(), "saved on another computer") {@@ -183,8 +183,9 @@ func TestNotebooksNeedTrust(t *testing.T) {
183183 t.Fatal(err)184184 }185185 out.Reset()186- if code, err := status(e, "get", path, "A2"); code != 0 || nu.ran != 2 || out.String() != "a.txt\n" {187- t.Errorf("the output saved: %d %v, ran %d, %q", code, err, nu.ran, out)186+ errOut.Reset()187+ if code, err := status(e, "get", path, "A2"); code != 0 || nu.ran != 2 || out.String() != "a.txt\n" || errOut.Len() > 0 {188+ t.Errorf("the output saved: %d %v, ran %d, %q %q", code, err, nu.ran, out, errOut)188189 }189190 if code, err := status(e, "get", path, "A2", "--notebooks"); code != 0 || nu.ran != 3 {190191 t.Errorf("trusted by recalc: %d %v, ran %d", code, err, nu.ran)@@ -129,7 +129,8 @@ things need more than the file:
129129 - **[Notebook](../nushell/notebooks.md) outputs** are kept in the file130130 as their cells last left them, and these commands read them as saved,131131 sent to sheets as on the screen; `get` notes on standard error when132- the sheet it reads shows outputs. `--notebooks` runs every notebook's132+ the sheet it reads has an output the file doesn't hold (never run, or133+ too large to save). `--notebooks` runs every notebook's133134 code cells first, each after the cells it reads, as F9 does; a cell134135 that fails stops the rest of its notebook, and is reported. A cell135136 reading `$selection` fails, having no selection to read.@@ -208,6 +208,23 @@ func feedOutput(w *sheet.Workbook, name string) {
208208 w.ApplyLive(op)209209 }210210 211+// MissingOutputs names the notebook outputs sent to s that show no rows212+// because the file holds no output for their cells: never run, too213+// large to save, or their cells gone.214+func MissingOutputs(s *sheet.Sheet) []string {215+ var out []string216+ for _, r := range s.Regions() {217+ if !r.Output {218+ continue219+ }220+ c, ok := cellNamed(s.Book(), r.Name)221+ if o := s.Book().Output(c.ID); !ok || o == nil || o.Unsaved {222+ out = append(out, r.Name)223+ }224+ }225+ return out226+}227+211228 // cellNamed is the notebook cell that gives its output name.212229 func cellNamed(w *sheet.Workbook, name string) (notebook.Cell, bool) {213230 for _, s := range w.Sheets() {