IF Commons GitHub

sql/cli/blocks

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0047-arcactl-init FR-002

Managed blocks (commons data 0047-arcactl-init FR-002): the one way arcactl changes a file that a person also edits. A block is a run of lines between two marker lines that name it; arcactl writes only inside its markers, so the rest of the file is the person's and is never touched. Putting a block in twice is the same as once, taking it out leaves the file as it was, and a file whose markers do not make sense (one is missing, or the block is there twice) is an error value and is not changed.

The line ending of the file is kept. Taking a block out restores the file exactly where the file ended with a line ending (or was empty) when the block was put in.

Source: commons/data/sql/cli/blocks.ts

4 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

blockOffunction
function blockOf(text: string, name: string, style: Style): Result<string | undefined, BlockError>

The body of a block, or none where it is not there.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

markersconst
const markers: (name: string, style: Style) => { readonly open: string; readonly close: string; }

The two marker lines of a block.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

Styletypeno test imports it
type Style = "#" | "--";

The comment mark of the file the block is in: # for most, -- for psql's.

withBlockfunction
function withBlock(text: string, name: string, style: Style, body: string): Result<string, BlockError>

The text with the block put in: replaced where it is there, added at the end where it is not.

ParameterWhat it is
textthe file's text
namethe block's name
stylethe file's comment mark
bodywhat is inside the markers, as lines

Returns: the new text, or what is wrong with the markers

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

withoutBlockfunction
function withoutBlock(text: string, name: string, style: Style): Result<string, BlockError>

The text with the block taken out, and the blank line that was put before it where there is one.

ParameterWhat it is
textthe file's text
namethe block's name
stylethe file's comment mark

Returns: the new text, or what is wrong with the markers

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.