in src/util/commandline/command.ts [147:184]
protected runNoClient(): Promise<Result.CommandResult> {
if (this.environmentName && !this.token) {
return Promise.resolve(Result.failure(Result.ErrorCodes.IllegalCommand, "Cannot specify environment without giving token"));
}
let client: AppCenterClient;
let endpoint: string;
if (this.token) {
debug(`Creating appcenter client for command from token for environment ${this.environmentName}`);
[client, endpoint] = this.getClientAndEndpointForToken(this.environmentName, this.token);
} else {
// creating client for either logged in user or environment variable token
const user = getUser();
const tokenFromEnvVar = getTokenFromEnvironmentVar();
const envFromEnvVar = getEnvFromEnvironmentVar();
const isLogoutCommand = this.command[0] === "logout";
if (user && tokenFromEnvVar && !isLogoutCommand) {
// logout command should be executed even if both user and env token are set - it just logs out user
return Promise.resolve(
Result.failure(
Result.ErrorCodes.IllegalCommand,
`logged in user and token in environment variable ${appCenterAccessTokenEnvVar} cannot be used together`
)
);
} else if (user) {
debug(`Creating appcenter client for command for current logged in user`);
client = this.clientFactory.fromProfile(user);
endpoint = user.endpoint;
} else if (tokenFromEnvVar) {
debug(`Creating appcenter client from token specified in environment variable for environment ${this.environmentName}`);
[client, endpoint] = this.getClientAndEndpointForToken(envFromEnvVar, tokenFromEnvVar);
}
}
if (client && endpoint) {
return this.run(client, getPortalUrlForEndpoint(endpoint));
}
return Promise.resolve(Result.notLoggedIn(`${scriptName} ${this.command.join(" ")}`));
}