(retrieve)
| 112 | } |
| 113 | |
| 114 | function getCommandData(retrieve) { |
| 115 | const data = { |
| 116 | positionals: [], |
| 117 | flags: [], |
| 118 | }; |
| 119 | const fn = { |
| 120 | alias(name, cmd) { |
| 121 | return this.swap(name, (flag) => ({ |
| 122 | ...flag, |
| 123 | alts: [...flag.alts, cmd], |
| 124 | })); |
| 125 | }, |
| 126 | positional(name, info) { |
| 127 | data.positionals.push({ |
| 128 | ...info, |
| 129 | name, |
| 130 | }); |
| 131 | return this; |
| 132 | }, |
| 133 | swap(name, swapper) { |
| 134 | const [flag] = data.flags.filter((m) => m.name === name); |
| 135 | const newFlag = swapper(flag || { name, alts: [] }); |
| 136 | |
| 137 | if (!flag) { |
| 138 | data.flags.push(newFlag); |
| 139 | } else { |
| 140 | Object.assign(flag, newFlag); |
| 141 | } |
| 142 | |
| 143 | return this; |
| 144 | }, |
| 145 | choices(name, choices) { |
| 146 | if (name === 'bundler') { |
| 147 | choices = bundlerNames; |
| 148 | } |
| 149 | |
| 150 | return this.swap(name, (flag) => ({ |
| 151 | ...flag, |
| 152 | type: 'string', |
| 153 | examples: [`--${name} ${printValue(choices[0])}`], |
| 154 | values: choices.map(printValue), |
| 155 | })); |
| 156 | }, |
| 157 | option(name) { |
| 158 | return this.swap(name, (flag) => ({ |
| 159 | ...flag, |
| 160 | examples: [`--${name}.foo bar`], |
| 161 | type: 'options', |
| 162 | })); |
| 163 | }, |
| 164 | string(name) { |
| 165 | return this.swap(name, (flag) => ({ |
| 166 | ...flag, |
| 167 | examples: [`--${name} "some value"`], |
| 168 | type: 'string', |
| 169 | })); |
| 170 | }, |
| 171 | boolean(name) { |
no test coverage detected