Documentation
¶
Overview ¶
Package headless works on workbook files without the screen, for 012 get, set, recalc and export (see docs/files/scripts.md): it opens a .012 file, finds the cells a reference names, reads and writes them, lists the errors formulas show and saves atomically. Nothing here runs a program or reaches the network unless its caller asks: notebook cells run through RunNotebooks and JEV functions through AnswerJEV, which the command line calls only behind flags.
Index ¶
- Variables
- func AnswerJEV(ctx context.Context, w *sheet.Workbook, client jev.Client, ...) int
- func Get(out io.Writer, t Target, o GetOptions) error
- func MissingOutputs(s *sheet.Sheet) []string
- func ResolveCell(w *sheet.Workbook, ref string) (*sheet.Sheet, sheet.Addr, error)
- func RunNotebooks(ctx context.Context, w *sheet.Workbook, o NotebookOptions) []string
- func Set(w *sheet.Workbook, entries []Entry, o SetOptions) (warnings []string, err error)
- func SyncOutputs(w *sheet.Workbook)
- func Trusted(w *sheet.Workbook, machine string) bool
- func WriteAtomic(path string, mode fs.FileMode, write func(io.Writer) error) error
- type Entry
- type File
- type GetOptions
- type NotebookOptions
- type Problem
- type SetOptions
- type Target
Constants ¶
This section is empty.
Variables ¶
var Formats = []string{"text", "csv", "tsv", "json", "nuon"}
Formats are what Get writes: text as the sheet shows it, or a table as 012 --pipe and exports write it.
Functions ¶
func AnswerJEV ¶
func AnswerJEV(ctx context.Context, w *sheet.Workbook, client jev.Client, timeout time.Duration) int
AnswerJEV answers w's JEV functions with client, asking what the workbook's formulas ask, a few questions at a time, until none is waiting, each within timeout. It returns how many were asked.
func Get ¶
func Get(out io.Writer, t Target, o GetOptions) error
Get writes the target's values. One cell is written alone: as it shows, or as a JSON or NUON value typed by its format (a number, a date, a file size). A range or sheet is written as a table: aligned columns as text, or as CSV, TSV, JSON or NUON, whose columns take their names from the first row (see GetOptions.NoHeader).
func MissingOutputs ¶
MissingOutputs names the notebook outputs sent to s that show no rows because the file holds no output for their cells: never run, too large to save, or their cells gone.
func ResolveCell ¶
ResolveCell is Resolve for a reference that must be one cell.
func RunNotebooks ¶
RunNotebooks runs the code cells of each notebook tab, each after the cells it reads, as Run all does on the screen: each cell's output replaces the one the file kept and goes on to the sheet it was sent to. A failure stops its notebook's run, as on the screen. It returns a line for each cell that failed or couldn't run.
func Set ¶
Set types each entry into its cell, in order, as one change. An entry a cell can't take (a formula that doesn't parse, a validation rule that rejects it, part of an array, a pivot table or a region, a protected range without Force) stops it with an error naming the cell, and the workbook should then be thrown away rather than saved. Entries a rule would only mark invalid are set, and returned as warnings.
func SyncOutputs ¶
SyncOutputs sends the outputs a file kept to the sheets they were sent to, as opening the file on the screen does: reading, not running.
Types ¶
type Entry ¶
type Entry struct {
Ref, Input string
}
Entry is one cell to set: a reference to one cell, and what to type in it, as the file stores entries (numbers and dates in en-US's form, formulas with commas, whatever the workbook's locale); "" clears it.
type File ¶
type File struct {
Path string
Book *sheet.Workbook
// New is set when there was no file at Path and Book is empty.
New bool
// contains filtered or unexported fields
}
File is a workbook opened from a .012 file.
func Open ¶
Open reads the workbook at path, with the notebook outputs it kept sent on to their sheets, as the screen opens it. With create, a path with no file opens as an empty workbook that Save writes there, as opening a new name in 012 does.
type GetOptions ¶
type GetOptions struct {
Format string // one of Formats; "" is text
// Input writes what was typed (a formula, or an entry as stored)
// rather than the value.
Input bool
// NoHeader names a JSON or NUON table's columns by their letters and
// makes every row a record, rather than taking the names from the
// first row.
NoHeader bool
}
GetOptions say how Get writes.
type NotebookOptions ¶
type NotebookOptions struct {
Runner nushell.Runner // nu, or a fake in tests
Timeout time.Duration // for each cell
NuConfig bool // run nu with the user's config files
}
NotebookOptions say how RunNotebooks runs cells.
type Problem ¶
type Problem struct {
Sheet string
Addr sheet.Addr
Value string // the error as the cell shows it: #DIV/0!
Why string // what the screen's context line says about it, or ""
// JEV is set when the error is a JEV function's with nothing to
// answer it: --jev asks the model.
JEV bool
}
Problem is a cell whose formula shows an error after recalculating.
func Errors ¶
Errors returns the cells of w showing errors, without recalculating. A cell an array spilled an error into is its formula's problem, so only formulas are listed.
type SetOptions ¶
type SetOptions struct {
// Force sets cells in protected ranges, which are refused otherwise,
// as the screen asks before editing them.
Force bool
}
SetOptions tune Set.
type Target ¶
Target is what a reference names: a range of one sheet, or the whole sheet (from A1 to its last cell with contents).
func Resolve ¶
Resolve finds what ref names in w: a cell or range (B7, A1:C9, A:A), on a sheet (Q3!B7, 'Q3 plan'!A1:C9) or else the sheet shown when the file was saved; a named range (Sales); a table by name, all of it with its header row, or by a structured reference as formulas read it (Sales[Amount]); or a sheet by name (Q3, or Q3!), meaning all of it. "" is the whole sheet shown.