From 290c72732f21f1cddb3a0f8ec3213e4ec321da14 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 15 Nov 2025 18:13:44 -0500 Subject: Add Path.lines() --- api/paths.yaml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'api/paths.yaml') diff --git a/api/paths.yaml b/api/paths.yaml index 532d9c71..8fbd18dc 100644 --- a/api/paths.yaml +++ b/api/paths.yaml @@ -107,14 +107,31 @@ Path.by_line: example: | # Safely handle file not being readable: if lines := (./file.txt).by_line() - for line in lines - say(line.upper()) + for line in lines + say(line.upper()) else - say("Couldn't read file!") + say("Couldn't read file!") # Assume the file is readable and error if that's not the case: for line in (/dev/stdin).by_line()! - say(line.upper()) + say(line.upper()) + +Path.lines: + short: return the lines in a file + description: > + Returns a list with the lines of text in a file or returns none if the file + could not be opened. + return: + type: '[Text]?' + description: > + A list of the lines in a file or none if the file couldn't be read. + args: + path: + type: 'Path' + description: > + The path of the file. + example: | + lines := (./file.txt).lines()! Path.can_execute: short: check execute permissions -- cgit v1.2.3