(argv: string[])
| 117 | } |
| 118 | |
| 119 | function parseProfileCommand(argv: string[]): RuntimeHostCliCommand { |
| 120 | const action = argv[0]; |
| 121 | if (action === 'list') { |
| 122 | return argv.length === 1 |
| 123 | ? { kind: 'runtime-host-profile-list' } |
| 124 | : error(`Unexpected argument: ${argv[1] ?? ''}`); |
| 125 | } |
| 126 | if (action === 'remove') { |
| 127 | if (argv[1] !== '--id') return error('runtime-host profile remove requires --id'); |
| 128 | const id = optionValue(argv, 1, '--id'); |
| 129 | if (typeof id !== 'string') return id; |
| 130 | return argv.length === 3 |
| 131 | ? { kind: 'runtime-host-profile-remove', id } |
| 132 | : error(`Unexpected argument: ${argv[3] ?? ''}`); |
| 133 | } |
| 134 | if (action !== 'set') { |
| 135 | return error( |
| 136 | action |
| 137 | ? `Unexpected runtime-host profile command: ${action}` |
| 138 | : 'runtime-host profile requires the list, set, or remove command', |
| 139 | ); |
| 140 | } |
| 141 | let id: string | undefined; |
| 142 | let name: string | undefined; |
| 143 | let tlsUrl: string | undefined; |
| 144 | let plaintextUrl: string | undefined; |
| 145 | let acknowledgePlaintext = false; |
| 146 | let sshDestination: string | undefined; |
| 147 | let sshPort: number | undefined; |
| 148 | let sshRemotePort: number | undefined; |
| 149 | let sshWebSocketPath = '/runtime-host'; |
| 150 | let sshWebSocketPathConfigured = false; |
| 151 | let expectedRootId: string | undefined; |
| 152 | let credentialEnv: string | undefined; |
| 153 | for (let index = 1; index < argv.length; index += 1) { |
| 154 | const argument = argv[index]; |
| 155 | if ( |
| 156 | argument !== '--id' && |
| 157 | argument !== '--name' && |
| 158 | argument !== '--tls-url' && |
| 159 | argument !== '--plaintext-url' && |
| 160 | argument !== '--ssh-destination' && |
| 161 | argument !== '--ssh-port' && |
| 162 | argument !== '--ssh-remote-port' && |
| 163 | argument !== '--ssh-websocket-path' && |
| 164 | argument !== '--expected-root' && |
| 165 | argument !== '--credential-env' && |
| 166 | argument !== '--acknowledge-plaintext' |
| 167 | ) { |
| 168 | return error(`Unexpected argument: ${argument ?? ''}`); |
| 169 | } |
| 170 | if (argument === '--acknowledge-plaintext') { |
| 171 | acknowledgePlaintext = true; |
| 172 | continue; |
| 173 | } |
| 174 | const parsed = optionValue(argv, index, argument); |
| 175 | if (typeof parsed !== 'string') return parsed; |
| 176 | if (argument === '--id') id = parsed; |
no test coverage detected