MCPcopy Index your code
hub / github.com/Effect-TS/effect / simplify

Function simplify

packages/cli/src/internal/usage.ts:101–151  ·  view source on GitHub ↗
(self: Usage.Usage, config: CliConfig.CliConfig)

Source from the content-addressed store, hash-verified

99// =============================================================================
100
101const simplify = (self: Usage.Usage, config: CliConfig.CliConfig): Usage.Usage => {
102 switch (self._tag) {
103 case "Empty": {
104 return empty
105 }
106 case "Mixed": {
107 return mixed
108 }
109 case "Named": {
110 if (Option.isNone(Arr.head(render(self, config)))) {
111 return empty
112 }
113 return self
114 }
115 case "Optional": {
116 if (self.usage._tag === "Empty") {
117 return empty
118 }
119 const usage = simplify(self.usage, config)
120 // No need to do anything for empty usage
121 return usage._tag === "Empty"
122 ? empty
123 // Avoid re-wrapping the usage in an optional instruction
124 : usage._tag === "Optional"
125 ? usage
126 : optional(usage)
127 }
128 case "Repeated": {
129 const usage = simplify(self.usage, config)
130 return usage._tag === "Empty" ? empty : repeated(usage)
131 }
132 case "Alternation": {
133 const leftUsage = simplify(self.left, config)
134 const rightUsage = simplify(self.right, config)
135 return leftUsage._tag === "Empty"
136 ? rightUsage
137 : rightUsage._tag === "Empty"
138 ? leftUsage
139 : alternation(leftUsage, rightUsage)
140 }
141 case "Concat": {
142 const leftUsage = simplify(self.left, config)
143 const rightUsage = simplify(self.right, config)
144 return leftUsage._tag === "Empty"
145 ? rightUsage
146 : rightUsage._tag === "Empty"
147 ? leftUsage
148 : concat(leftUsage, rightUsage)
149 }
150 }
151}
152
153const render = (self: Usage.Usage, config: CliConfig.CliConfig): Array<Span.Span> => {
154 switch (self._tag) {

Callers 1

usage.tsFile · 0.85

Calls 5

headMethod · 0.80
renderFunction · 0.70
optionalFunction · 0.70
repeatedFunction · 0.70
concatFunction · 0.50

Tested by

no test coverage detected