unison-cli-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.CommandLine.BranchRelativePath

Synopsis

Documentation

parseBranchRelativePath :: String -> Either (Pretty ColorText) BranchRelativePath Source #

Strings without colons are parsed as loose code paths. A path with a colon may specify: 1. A project and branch 2. Only a branch, in which case the project is assumed to be the current project 3. Only a path, in which case the path is rooted at the branch root

Specifying only a project is not allowed.

>>> parseBranchRelativePath "foo"
Right (UnqualifiedPath foo)
>>> parseBranchRelativePath "foo/bar:"
Right (QualifiedBranchPath (UnsafeProjectName "foo") (UnsafeProjectBranchName "bar") .)
>>> parseBranchRelativePath "foo/bar:.some.path"
Right (QualifiedBranchPath (UnsafeProjectName "foo") (UnsafeProjectBranchName "bar") .some.path)
>>> parseBranchRelativePath "/bar:.some.path"
Right (BranchPathInCurrentProject (UnsafeProjectBranchName "bar") .some.path)
>>> parseBranchRelativePath ":.some.path"
Right (UnqualifiedPath .some.path)
>>> parseBranchRelativePath ".branch"
Right (UnqualifiedPath .branch)

parseIncrementalBranchRelativePath :: String -> Either (Pretty ColorText) IncrementalBranchRelativePath Source #

>>> parseIncrementalBranchRelativePath "foo"
Right (ProjectOrRelative "foo" foo)
>>> parseIncrementalBranchRelativePath "foo/bar:"
Right (IncompletePath (Left (ProjectAndBranch {project = UnsafeProjectName "foo", branch = UnsafeProjectBranchName "bar"})) Nothing)
>>> parseIncrementalBranchRelativePath "foo/bar:some.path"
Right (IncompletePath (Left (ProjectAndBranch {project = UnsafeProjectName "foo", branch = UnsafeProjectBranchName "bar"})) (Just some.path))
>>> parseIncrementalBranchRelativePath "/bar:some.path"
Right (IncompletePath (Right (UnsafeProjectBranchName "bar")) (Just some.path))
>>> parseIncrementalBranchRelativePath ":some.path"
Right (PathRelativeToCurrentBranch some.path)
>>> parseIncrementalBranchRelativePath "/branch"
Right (IncompleteBranch Nothing (Just (UnsafeProjectBranchName "branch")))
>>> parseIncrementalBranchRelativePath "/"
Right (IncompleteBranch Nothing Nothing)

data IncrementalBranchRelativePath Source #

Constructors

ProjectOrPath' Text Path'

no dots, slashes, or colons, so could be a project name or a single path segment

OnlyPath' Path'

dots, no slashes or colons, must be a relative or absolute path

IncompleteProject ProjectName

valid project, no slash

IncompleteBranch (Maybe ProjectName) (Maybe ProjectBranchName)

valid project/branch, slash, no colon

IncompletePath (Either (ProjectAndBranch ProjectName ProjectBranchName) ProjectBranchName) (Maybe Absolute)

valid project/branch, with colon

PathRelativeToCurrentBranch Absolute