v12 preparations: Add version switch, update login message.

Change-type: patch
Connects-to: #1770
Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
Scott Lowe 2020-05-27 13:05:49 +02:00
parent 56a196210d
commit 889c7b08cf
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,10 +81,16 @@ 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())) {
throw new NotLoggedInError(stripIndent` if (isVersionGTE('12.0.0')) {
throw new NotLoggedInError(stripIndent`
Login required: use the balena login command to log in.
`);
} else {
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`);
}
} }
} }