Merge pull request #1845 from balena-io/change-login-message

v12 preparations - Add versionOverride function, change login message
This commit is contained in:
bulldozer-balena[bot] 2020-05-27 16:55:44 +00:00 committed by GitHub
commit 2cad44915b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -25,6 +25,9 @@ import * as ShellEscape from 'shell-escape';
import { ExpectedError } from '../errors'; import { ExpectedError } from '../errors';
import { getBalenaSdk, getChalk, getVisuals } from './lazy'; import { getBalenaSdk, getChalk, getVisuals } from './lazy';
import * as semver from 'semver';
import { version } from '../../package.json';
export function getGroupDefaults(group: { export function getGroupDefaults(group: {
options: Array<{ name: string; default?: string }>; options: Array<{ name: string; default?: string }>;
}): { [name: string]: string | number | undefined } { }): { [name: string]: string | number | undefined } {
@ -465,3 +468,7 @@ export function getProxyConfig(): ProxyConfig | undefined {
} }
} }
} }
export function isVersionGTE(v: string) {
return semver.gte(process.env.BALENA_CLI_VERSION_OVERRIDE || version, v);
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2016-2019 Balena Copyright 2016-2020 Balena
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import _ = require('lodash');
import _form = require('resin-cli-form'); import _form = require('resin-cli-form');
import { exitWithExpectedError, instanceOf, NotLoggedInError } from '../errors'; import { exitWithExpectedError, instanceOf, NotLoggedInError } from '../errors';
import { isVersionGTE } from './helpers';
import { getBalenaSdk, getVisuals } from './lazy'; import { getBalenaSdk, getVisuals } from './lazy';
import validation = require('./validation'); import validation = require('./validation');
@ -80,11 +81,17 @@ export function authenticate(options: {}): Bluebird<void> {
export async function checkLoggedIn(): Promise<void> { export async function checkLoggedIn(): Promise<void> {
const balena = getBalenaSdk(); const balena = getBalenaSdk();
if (!(await balena.auth.isLoggedIn())) { if (!(await balena.auth.isLoggedIn())) {
if (isVersionGTE('12.0.0')) {
throw new NotLoggedInError(stripIndent`
Login required: use the balena login command to log in.
`);
} else {
throw new NotLoggedInError(stripIndent` throw new NotLoggedInError(stripIndent`
You have to log in to continue You have to log in to continue
Run the following command to go through the login wizard: Run the following command to go through the login wizard:
$ balena login`); $ balena login`);
} }
}
} }
export function askLoginType() { export function askLoginType() {