Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Projects.
The syntax-related parsing code (what makes a valid project name, etc) could conceivably be moved into a different package, but for now we have just defined the one blessed project/branch name syntax that we allow.
Synopsis
- data ProjectName
- projectNameUserSlug :: ProjectName -> Maybe Text
- projectNameToUserProjectSlugs :: ProjectName -> (Text, Text)
- prependUserSlugToProjectName :: Text -> ProjectName -> ProjectName
- data ProjectBranchName
- projectBranchNameUserSlug :: ProjectBranchName -> Maybe Text
- data ProjectBranchNameKind
- classifyProjectBranchName :: ProjectBranchName -> ProjectBranchNameKind
- data ProjectBranchNameOrLatestRelease
- data ProjectBranchSpecifier :: Type -> Type where
- data ProjectAndBranch a b = ProjectAndBranch {}
- projectAndBranchNamesParser :: forall branch. ProjectBranchSpecifier branch -> Parsec Void Text (These ProjectName branch)
- fullyQualifiedProjectAndBranchNamesParser :: Parsec Void Text (ProjectAndBranch ProjectName ProjectBranchName)
- projectAndOptionalBranchParser :: forall branch. ProjectBranchSpecifier branch -> Parsec Void Text (ProjectAndBranch ProjectName (Maybe branch))
- branchWithOptionalProjectParser :: Parsec Void Text (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
- data ProjectAndBranchNames
- projectAndBranchNamesParser2 :: Parsec Void Text ProjectAndBranchNames
- projectNameParser :: Parsec Void Text (ProjectName, Bool)
- projectBranchNameParser :: Bool -> Parsec Void Text ProjectBranchName
- data Semver = Semver !Int !Int !Int
Documentation
data ProjectName #
The name of a project.
Instances
projectNameUserSlug :: ProjectName -> Maybe Text Source #
Get the user slug at the beginning of a project name, if there is one.
>>>
projectNameUserSlug "@arya/lens"
Just "arya"
>>>
projectNameUserSlug "lens"
Nothing
projectNameToUserProjectSlugs :: ProjectName -> (Text, Text) Source #
Parse a "@arya/lens" into the "arya" and "lens" parts.
If there's no "arya" part, returns the empty string there.
>>>
projectNameToUserProjectSlugs (UnsafeProjectName "@arya/lens")
("arya","lens")
>>>
projectNameToUserProjectSlugs (UnsafeProjectName "lens")
("","lens")
prependUserSlugToProjectName :: Text -> ProjectName -> ProjectName Source #
Prepend a user slug to a project name, if it doesn't already have one.
>>>
prependUserSlugToProjectName "arya" "lens"
"@arya/lens"
>>>
prependUserSlugToProjectName "runar" "@unison/base"
"@unison/base"
>>>
prependUserSlugToProjectName "???invalid???" "@unison/base"
"@unison/base"
data ProjectBranchName #
The name of a branch of a project.
Instances
projectBranchNameUserSlug :: ProjectBranchName -> Maybe Text Source #
Get the user slug at the beginning of a project branch name, if there is one.
>>>
projectBranchNameUserSlug "@arya/topic"
Just "arya"
>>>
projectBranchNameUserSlug "topic"
Nothing
data ProjectBranchNameKind Source #
Though a branch name is just a flat string, we have logic that handles certain strings specially.
A branch's name indicates it is exactly one of the following:
- A contributor branch like "@arya/topic"
- A draft release branch like "releasesdrafts1.2.3"
- A release branch like "releases/1.2.3"
- None of the above, like "topic"
Note these classifications are only tied to the branch's (mutable) name, and are not really otherwise indicative of much.
For instance,
- The existence of a local "releases/1.2.3" branch does not necessarily imply the existence of some remote release version "1.2.3".
- The existence of a local "
arya/topic
branch does not necessarily imply the existence of some remote "arya" user made some "topic" branch at some point.
That said, we do try to make the system mostly make sense by rejecting certain inputs (e.g. you should not be able to easily create a local branch called "releases/1.2.3" out of thin air; you should have to clone it from somewhere). But ultimately, again, branch names are best thought of as opaque, flat strings.
classifyProjectBranchName :: ProjectBranchName -> ProjectBranchNameKind Source #
Classify a project branch name.
>>>
classifyProjectBranchName "@arya/topic"
Contributor "arya" "topic"
>>>
classifyProjectBranchName "releases/drafts/1.2.3"
DraftRelease (Semver 1 2 3)
>>>
classifyProjectBranchName "releases/1.2.3"
Release (Semver 1 2 3)
>>>
classifyProjectBranchName "topic"
NothingSpecial
data ProjectBranchNameOrLatestRelease Source #
A project branch name, or the latest release of its project.
ProjectBranchNameOrLatestRelease'LatestRelease | |
ProjectBranchNameOrLatestRelease'Name !ProjectBranchName |
data ProjectBranchSpecifier :: Type -> Type where Source #
How a project branch can be specified.
ProjectBranchSpecifier'Name :: ProjectBranchSpecifier ProjectBranchName | By name. |
ProjectBranchSpecifier'NameOrLatestRelease :: ProjectBranchSpecifier ProjectBranchNameOrLatestRelease | By name, or "the latest release" |
data ProjectAndBranch a b #
A generic data structure that contains information about a project and a branch in that project.
Instances
projectAndBranchNamesParser :: forall branch. ProjectBranchSpecifier branch -> Parsec Void Text (These ProjectName branch) Source #
fullyQualifiedProjectAndBranchNamesParser :: Parsec Void Text (ProjectAndBranch ProjectName ProjectBranchName) Source #
Parse a fully specified myproject/mybranch name.
>>>
import Text.Megaparsec (parseMaybe)
>>>
parseMaybe fullyQualifiedProjectAndBranchNamesParser ("myproject/mybranch" :: Text)
Just (ProjectAndBranch {project = UnsafeProjectName "myproject", branch = UnsafeProjectBranchName "mybranch"})
projectAndOptionalBranchParser :: forall branch. ProjectBranchSpecifier branch -> Parsec Void Text (ProjectAndBranch ProjectName (Maybe branch)) Source #
branchWithOptionalProjectParser :: Parsec Void Text (ProjectAndBranch (Maybe ProjectName) ProjectBranchName) Source #
data ProjectAndBranchNames Source #
Sometimes, it's convenient (to users) if we defer interpreting certain names (like "foo") as a project name or branch name, instead leaving it up to a command handler to handle the ambiguity.
For example, we might want "switch foo" to switch to either the project "foo", or the branch "foo", or complain if both exist.
This type is useful for those situtations.
ProjectAndBranchNames'Ambiguous ProjectName ProjectBranchName | |
ProjectAndBranchNames'Unambiguous (These ProjectName ProjectBranchName) |
Instances
Show ProjectAndBranchNames Source # | |
Defined in Unison.Project showsPrec :: Int -> ProjectAndBranchNames -> ShowS # show :: ProjectAndBranchNames -> String # showList :: [ProjectAndBranchNames] -> ShowS # | |
Eq ProjectAndBranchNames Source # | |
Defined in Unison.Project (==) :: ProjectAndBranchNames -> ProjectAndBranchNames -> Bool # (/=) :: ProjectAndBranchNames -> ProjectAndBranchNames -> Bool # | |
TryFrom Text ProjectAndBranchNames Source # | |
Defined in Unison.Project |