mirror of
https://github.com/desktop/desktop
synced 2024-09-19 08:02:22 +00:00
Simplify trampoline command parsing: pick identifier from env
This commit is contained in:
parent
2151b42920
commit
d8dcb45248
|
@ -8,7 +8,7 @@ export function envForAuthentication(auth: IGitAccount | null): Object {
|
|||
const env = {
|
||||
DESKTOP_PATH: process.execPath,
|
||||
DESKTOP_ASKPASS_SCRIPT: getAskPassScriptPath(),
|
||||
DESKTOP_IDENTIFIER: 'ASKPASS',
|
||||
DESKTOP_TRAMPOLINE_IDENTIFIER: 'ASKPASS',
|
||||
GIT_ASKPASS: getAskPassTrampolinePath(),
|
||||
// supported since Git 2.3, this is used to ensure we never interactively prompt
|
||||
// for credentials - even as a fallback
|
||||
|
|
|
@ -9,7 +9,6 @@ interface ITrampolineCommand {
|
|||
}
|
||||
|
||||
enum TrampolineCommandParserState {
|
||||
Identifier,
|
||||
ParameterCount,
|
||||
Parameters,
|
||||
EnvironmentVariablesCount,
|
||||
|
@ -18,14 +17,13 @@ enum TrampolineCommandParserState {
|
|||
}
|
||||
|
||||
class TrampolineCommandParser {
|
||||
private identifier: string | null = null
|
||||
private parameterCount: number = 0
|
||||
private readonly parameters: string[] = []
|
||||
private environmentVariablesCount: number = 0
|
||||
private readonly environmentVariables = new Map<string, string>()
|
||||
|
||||
private state: TrampolineCommandParserState =
|
||||
TrampolineCommandParserState.Identifier
|
||||
TrampolineCommandParserState.ParameterCount
|
||||
|
||||
public hasFinished() {
|
||||
return this.state === TrampolineCommandParserState.Finished
|
||||
|
@ -33,12 +31,6 @@ class TrampolineCommandParser {
|
|||
|
||||
public processValue(value: string) {
|
||||
switch (this.state) {
|
||||
case TrampolineCommandParserState.Identifier:
|
||||
this.identifier = value
|
||||
console.log(`Trampoline parsed identifier ${value}`)
|
||||
this.state = TrampolineCommandParserState.ParameterCount
|
||||
break
|
||||
|
||||
case TrampolineCommandParserState.ParameterCount:
|
||||
this.parameterCount = parseInt(value)
|
||||
console.log(`Trampoline parsed parameterCount ${value}`)
|
||||
|
@ -108,10 +100,12 @@ class TrampolineCommandParser {
|
|||
)
|
||||
}
|
||||
|
||||
const identifier = this.identifier
|
||||
const identifier = this.environmentVariables.get(
|
||||
'DESKTOP_TRAMPOLINE_IDENTIFIER'
|
||||
)
|
||||
|
||||
if (identifier === null) {
|
||||
throw new Error('The command identifier cannot be null')
|
||||
if (identifier === undefined) {
|
||||
throw new Error('The command identifier is missing')
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue