~/bend-docscommunity

src/ez/target.bend checks

raw source on the hub · import 0x886223f5c47e4983fe57d887c034bc7f/src/ez/target.bend as Target

ez/target: what ez add, ez tool run, install and upgrade were asked for, decided from the word alone. owner/repo is GitHub. A URL is that URL. Anything else is a path, and a path written ./…, ../…, /… or ~/… is a path even when it would otherwise read as a repository. For ez add, a word bend reads as a hub package's <name>@<version> names that package, where it would otherwise be a path (aim).

2 imports
import Base
import ../pkg/pkg.bend as K

Types

type Place source · line 11 · raw

Data

where a target names, or why it names nothing

type Mark source · line 26 · raw

Data

what one char of a target is, as far as telling a shorthand from a path goes. A colon is asked about first, so a char that is anything but Other is known not to be one: that is what lets a proof say a shorthand never contains ://.

type Halves source · line 151 · raw

Data

a word cut at its first slash, or not cut because a char before any slash could not be in a shorthand

type Aim source · line 391 · raw

Data

what ez add was asked for: a hub package by its <name>@<version>, or a place as classify reads it

Definitions

def plain.at source · line 18 · raw

@+ch:Char -> Bool

a char a GitHub owner or repository may hold besides a dot: a letter, a digit, - or _

def kind.word source · line 33 · raw

@word:Bool -> Mark

def kind.tilde source · line 40 · raw

@tilde:Bool -> @word:Bool -> Mark

def kind.dot source · line 47 · raw

@dot:Bool -> @tilde:Bool -> @word:Bool -> Mark

def kind.slash source · line 54 · raw

@slash:Bool -> @dot:Bool -> @tilde:Bool -> @word:Bool -> Mark

def kind.colon source · line 61 · raw

@colon:Bool -> @slash:Bool -> @dot:Bool -> @tilde:Bool -> @word:Bool -> Mark

def kind source · line 69 · raw

@+ch:Char -> Mark

a char's kind

def name.keep source · line 75 · raw

@mark:Mark -> @rest:(@_:Unit -> Bool) -> Bool

one char of a name, with the rest of the name still to be asked about. The rest arrives as a thunk, so a char that ends the name ends the walk.

def name.all source · line 89 · raw

@text:String -> Bool

every char a letter, a digit, -, _ or .

def seg.dots source · line 97 · raw

@text:String -> Bool

after ..: one more name char, so the segment is not ..

def seg.dot2 source · line 105 · raw

@mark:Mark -> @rest:String -> Bool

the second char after a leading dot

def seg.dot source · line 119 · raw

@text:String -> Bool

after a leading .: more, so the segment is not .

def seg.first source · line 127 · raw

@mark:Mark -> @rest:String -> Bool

the first char of a segment

def seg source · line 142 · raw

@text:String -> Bool

one segment of a GitHub shorthand: letters, digits, -, _ and ., at least one of them, and not . or .., which name a directory

def halve.put source · line 156 · raw

@ch:Char -> @halves:Halves -> Halves

a char put back in front of the left half

def halve.at source · line 165 · raw

@mark:Mark -> @ch:Char -> @+tail:String -> @rest:(@_:Unit -> Halves) -> Halves

one char of the first segment. A slash ends it; the rest of the word is asked about only past a char a segment may hold.

def halve source · line 179 · raw

@text:String -> Halves

the word before its first slash and the word after it

def bend.file source · line 188 · raw

@+text:String -> Bool

a word naming a Bend file. As the second of two segments it is the last component of a path, src/main.bend, and not a repository.

def repo.seg source · line 192 · raw

@+text:String -> Bool

the second segment of a shorthand: a segment that is not a Bend file

def github.halves source · line 196 · raw

@halves:Halves -> Bool

both segments of a shorthand, where there are two

def github.ok source · line 206 · raw

@text:String -> Bool

owner/repo: exactly two segments, each a seg, the second not ending in .bend. A second slash leaves the right half with a slash in it, which no segment holds.

def climb.step source · line 210 · raw

@here:Bool -> @rest:(@_:Unit -> Bool) -> Bool

one step of a scan looking for ... A slug with one would leave the cache.

def climb source · line 218 · raw

@ps:List<&2, String> -> Bool

whether any component is a climb

def slug.ok source · line 226 · raw

@+text:String -> Bool

a slug that stays under the cache: non-empty, relative, and with no ..

def remote source · line 232 · raw

@+url:String -> @+slug:String -> Place

a remote whose slug can be a directory, or a refusal when it cannot

def cut.end source · line 237 · raw

@+text:String -> @+suf:String -> @len:Nat -> String

s with a suffix of n chars taken off when it ends in that suffix. Bool.pick builds both arms, which is the same trade pkg/path.unbend makes.

def unslash source · line 242 · raw

@+text:String -> String

a trailing slash is not part of the cache directory

def ungit source · line 246 · raw

@+text:String -> String

a trailing .git is not part of the cache directory

def body source · line 251 · raw

@ps:List<&2, String> -> String

everything after the first colon. https://host/path splits into the scheme and //host/path.

def drop.slashes source · line 259 · raw

@+text:String -> String

the // a scheme leaves in front of the host

def hostless source · line 264 · raw

@+text:String -> String

a URL with no host, file:///srv/repo, is on this host, and is cached where file://localhost/srv/repo is, rather than at an absolute slug

def slug.url source · line 268 · raw

@+text:String -> String

scheme://host/path as a cache directory

def slug.scp source · line 272 · raw

@+text:String -> String

git@host:path as a cache directory. The colon is the only separator.

def looks.slash.at source · line 276 · raw

@mark:Mark -> Bool

the char after ~ or ..: a slash

def looks.slash source · line 289 · raw

@text:String -> Bool

def looks.dot.at source · line 297 · raw

@mark:Mark -> @rest:String -> Bool

the char after a leading dot: ./ or ../

def looks.dot source · line 310 · raw

@text:String -> Bool

def looks.first source · line 318 · raw

@mark:Mark -> @rest:String -> Bool

the first char: /, or the start of ./, ../ or ~/

def looks.path source · line 332 · raw

@text:String -> Bool

a word that already says it is a path: it starts /, ./, ../ or ~/

def classify.scp source · line 340 · raw

@scp:Bool -> @+text:String -> Place

git@host:path, or a path

def classify.hub source · line 350 · raw

@ok:Bool -> @+text:String -> Place

owner/repo. Its slug is safe without the check a URL's gets: neither segment is empty, ., .. or holds a slash, so it cannot climb out of the cache. A trailing .git is not part of the cache directory, as for a URL.

def classify.path source · line 358 · raw

@local:Bool -> @+text:String -> Place

a path prefix, or a possible shorthand

def classify.url source · line 366 · raw

@url:Bool -> @+text:String -> Place

a URL, or not

def classify.empty source · line 374 · raw

@empty:Bool -> @+text:String -> Place

nothing was asked for

def classify source · line 386 · raw

@+text:String -> Place

what a target word names. A word with :// in it is a URL; one starting /, ./, ../ or ~/ is a path; owner/repo is GitHub; one starting git@ is a URL; anything else is a path. The shorthand is asked about before git@ because no shorthand holds an @, and in that order the shorthand's law needs nothing said about git@.

def aim.local source · line 397 · raw

@named:Bool -> @+text:String -> @+path:String -> Aim

a word classify reads as a path names a hub package when bend's NAMED rule rules it in (K.name.ok); otherwise it is that path

def aim.place source · line 407 · raw

@place:Place -> @+text:String -> Aim

the place read, with only a path asked whether it is a name. A URL, a git@host:path and an owner/repo are never read again, so nothing that was a remote becomes a name.

def aim source · line 419 · raw

@+text:String -> Aim

what an ez add target names. A name holds no / and no :, and starts with a letter, so a word bend reads as a name is one classify reads as a path, and only such a word is asked.

def aim.named source · line 423 · raw

@aim:Aim -> Bool

whether a target names a hub package

def expand source · line 431 · raw

@+home:String -> @+path:String -> String

~ and ~/… expanded. Anything else is already a path.

def entry.or source · line 437 · raw

@+path:String -> String

the entry, or main.bend when a ledger names none

def file.of source · line 441 · raw

@+bin:String -> @+entry:String -> String

the file that is built: bin when the ledger names one, otherwise the entry

def out.name source · line 445 · raw

@+name:String -> String

the binary's name: the package's, or app when the ledger names none

def show source · line 449 · raw

@place:Place -> String

a place on one line, for a proof to read