@@ -30,8 +30,32 @@ const parsePort = (value: string): Either.Either<number, ParseError> => {
3030 return Either . right ( parsed )
3131}
3232
33+ /**
34+ * Parses a raw SSH port value into the valid Docker host-port range.
35+ *
36+ * @param value - Raw textual value for `--ssh-port`.
37+ * @returns Either a valid integer port or a typed parse error for `--ssh-port`.
38+ * @pure true
39+ * @effect none; CORE parser only evaluates the provided string.
40+ * @invariant Right(port) implies Number.isInteger(port) and 1 <= port <= 65535.
41+ * @precondition value is untrusted CLI or config text.
42+ * @postcondition the function returns a typed Either and never throws.
43+ * @complexity O(1) time / O(1) space.
44+ */
3345export const parseSshPort = ( value : string ) : Either . Either < number , ParseError > => parsePort ( value )
3446
47+ /**
48+ * Parses and validates the SSH user used by generated Dockerfiles and entrypoints.
49+ *
50+ * @param value - Optional raw value for `--ssh-user`; undefined falls back to the default template user.
51+ * @returns Either a Linux user name matching the docker-git invariant or a typed parse error.
52+ * @pure true
53+ * @effect none; CORE parser only trims and validates the candidate string.
54+ * @invariant Right(user) implies user matches ^[a-z_][a-z0-9_-]{0,31}$.
55+ * @precondition value is untrusted CLI or config text.
56+ * @postcondition empty candidates fail as MissingRequiredOption; unsafe candidates fail as InvalidOption.
57+ * @complexity O(n) time / O(1) space where n = |value|.
58+ */
3559export const parseSshUser = (
3660 value : string | undefined
3761) : Either . Either < string , ParseError > => {
@@ -52,6 +76,18 @@ export const parseSshUser = (
5276 return Either . right ( candidate )
5377}
5478
79+ /**
80+ * Parses the Docker network mode selector used by generated compose files.
81+ *
82+ * @param value - Optional raw value for `--network-mode`; undefined falls back to the template default.
83+ * @returns Either a supported network mode or a typed parse error for `--network-mode`.
84+ * @pure true
85+ * @effect none; CORE parser only trims and checks a finite domain.
86+ * @invariant Right(mode) implies mode is either "shared" or "project".
87+ * @precondition value is untrusted CLI or config text.
88+ * @postcondition unsupported modes fail as InvalidOption.
89+ * @complexity O(n) time / O(1) space where n = |value|.
90+ */
5591export const parseDockerNetworkMode = (
5692 value : string | undefined
5793) : Either . Either < CreateCommand [ "config" ] [ "dockerNetworkMode" ] , ParseError > => {
@@ -66,6 +102,18 @@ export const parseDockerNetworkMode = (
66102 } )
67103}
68104
105+ /**
106+ * Parses the GPU mode selector used by generated compose files.
107+ *
108+ * @param value - Optional raw value for `--gpu`; undefined falls back to the template default.
109+ * @returns Either a supported GPU mode or a typed parse error for `--gpu`.
110+ * @pure true
111+ * @effect none; CORE parser only trims and checks a finite domain.
112+ * @invariant Right(mode) implies mode is either "none" or "all".
113+ * @precondition value is untrusted CLI or config text.
114+ * @postcondition unsupported modes fail as InvalidOption.
115+ * @complexity O(n) time / O(1) space where n = |value|.
116+ */
69117export const parseGpuMode = (
70118 value : string | undefined
71119) : Either . Either < CreateCommand [ "config" ] [ "gpu" ] , ParseError > => {
@@ -80,6 +128,20 @@ export const parseGpuMode = (
80128 } )
81129}
82130
131+ /**
132+ * Parses a required non-empty string option with an optional fallback.
133+ *
134+ * @param option - CLI option name reported in typed parse errors.
135+ * @param value - Optional raw value supplied by the user.
136+ * @param fallback - Optional default used when value is undefined.
137+ * @returns Either the trimmed non-empty candidate or a typed missing-option error.
138+ * @pure true
139+ * @effect none; CORE parser only trims and checks string length.
140+ * @invariant Right(candidate) implies candidate.length > 0.
141+ * @precondition option names the boundary field being decoded.
142+ * @postcondition missing or empty candidates fail as MissingRequiredOption.
143+ * @complexity O(n) time / O(1) space where n = |value|.
144+ */
83145export const nonEmpty = (
84146 option : string ,
85147 value : string | undefined ,
0 commit comments