Skip to content

Commit

Permalink
Merge pull request #88 from 8base/fix-error-message
Browse files Browse the repository at this point in the history
fix configure error text
  • Loading branch information
esemushin authored Dec 22, 2020
2 parents 1c8d76f + 6d9b668 commit 18f6398
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 28 deletions.
6 changes: 2 additions & 4 deletions e2e/tests/__snapshots__/help.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ OPTIONS
--debug, -d Turn on debug logs [boolean]
--help, -h Show help [boolean]
--workspaceId, -w The workspace ID of the project [string]
--region, -r The workspace region of the project [string]
--host The workspace host of the project [string]"
--host The workspace host of the project [string] [default: \\"https://api.8base.com\\"]"
`;
exports[`As a user, I can use help flag for see help information about \`deploy\`. 1`] = `
Expand Down Expand Up @@ -320,8 +319,7 @@ OPTIONS
--syntax, -s Syntax for the generated file [string] [choices: \\"js\\", \\"ts\\"] [default: \\"ts\\"]
--silent Disable printing extra info to the console [boolean] [default: false]
--workspaceId, -w The workspace ID of the project [string]
--region, -r The workspace region of the project [string]
--host The workspace host of the project [string]
--host The workspace host of the project [string] [default: \\"https://api.8base.com\\"]
EXAMPLES
8base init Initializes project in current folder
Expand Down
5 changes: 2 additions & 3 deletions src/common/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const pkg = require('../../package.json');
export type WorkspaceConfig = {
readonly workspaceId: string;
readonly environmentName: string;
readonly region: string;
readonly apiHost: string;
};

Expand Down Expand Up @@ -256,7 +255,7 @@ export class Context {
isLoginRequired: true,
customWorkspaceId: undefined,
customEnvironment: undefined,
address: this.apiHost,
address: this.apiHost || this.resolveMainServerAddress(),
};

const { customEnvironment, customWorkspaceId, isLoginRequired, address } = options
Expand All @@ -273,7 +272,7 @@ export class Context {
address has to be passed as parameter (workspace list query) or resolved from workspace info
another way it's invalid behaviour
*/
throw new Error(this.i18n.t('logout_error'));
throw new Error(this.i18n.t('configure_error'));
}

const client = new Client(address);
Expand Down
17 changes: 8 additions & 9 deletions src/engine/commands/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import * as yargs from 'yargs';
import { Context } from '../../../common/context';
import { translations } from '../../../common/translations';
import { Interactive } from '../../../common/interactive';
import { DEFAULT_ENVIRONMENT_NAME } from '../../../consts/Environment';
import { DEFAULT_ENVIRONMENT_NAME, DEFAULT_REMOTE_ADDRESS } from '../../../consts/Environment';
import _ = require('lodash');
import { Workspace } from '../../../interfaces/Common';

export default {
command: 'configure',

handler: async (params: any, context: Context) => {
let { workspaceId, region, host } = params;
let { workspaceId, host } = params;

const workspaces = await context.getWorkspaces();

Expand All @@ -34,11 +34,14 @@ export default {
throw new Error(context.i18n.t('workspace_with_id_doesnt_exist', { id: workspaceId }));
}

region = workspace.region;
host = workspace.apiHost;
}

context.updateWorkspace({ region, workspaceId, environmentName: DEFAULT_ENVIRONMENT_NAME, apiHost: host });
context.updateWorkspace({
apiHost: host || DEFAULT_REMOTE_ADDRESS,
workspaceId,
environmentName: DEFAULT_ENVIRONMENT_NAME,
});
},

describe: translations.i18n.t('configure_describe'),
Expand All @@ -51,13 +54,9 @@ export default {
describe: translations.i18n.t('configure_workspace_id_describe'),
type: 'string',
})
.option('region', {
alias: 'r',
describe: translations.i18n.t('configure_workspace_region_describe'),
type: 'string',
})
.option('host', {
describe: translations.i18n.t('configure_workspace_host_describe'),
type: 'string',
default: DEFAULT_REMOTE_ADDRESS,
}),
};
17 changes: 8 additions & 9 deletions src/engine/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Colors } from '../../../consts/Colors';
import { ProjectController } from '../../controllers/projectController';
import { ExtensionType, SyntaxType } from '../../../interfaces/Extensions';
import { Interactive } from '../../../common/interactive';
import { DEFAULT_ENVIRONMENT_NAME } from '../../../consts/Environment';
import { DEFAULT_ENVIRONMENT_NAME, DEFAULT_REMOTE_ADDRESS } from '../../../consts/Environment';
import { Workspace } from '../../../interfaces/Common';

const CREATE_WORKSPACE_MUTATION = `
Expand All @@ -41,7 +41,7 @@ export default {
handler: async (params: any, context: Context) => {
const { functions, empty, syntax, mocks, silent } = params;

let { workspaceId, region, host } = params;
let { workspaceId, host } = params;

const [, projectName] = _.castArray(params._);

Expand Down Expand Up @@ -140,7 +140,6 @@ export default {
throw new Error(context.i18n.t('workspace_with_id_doesnt_exist', { id: workspaceId }));
}

region = workspace.region;
host = workspace.apiHost;
}

Expand Down Expand Up @@ -187,7 +186,11 @@ export default {
}

context.createWorkspaceConfig(
{ workspaceId, environmentName: DEFAULT_ENVIRONMENT_NAME, region, apiHost: host },
{
workspaceId,
environmentName: DEFAULT_ENVIRONMENT_NAME,
apiHost: host || DEFAULT_REMOTE_ADDRESS,
},
project.fullPath,
);

Expand Down Expand Up @@ -245,14 +248,10 @@ export default {
describe: translations.i18n.t('init_workspace_id_describe'),
type: 'string',
})
.option('region', {
alias: 'r',
describe: translations.i18n.t('init_workspace_region_describe'),
type: 'string',
})
.option('host', {
describe: translations.i18n.t('init_workspace_host_describe'),
type: 'string',
default: DEFAULT_REMOTE_ADDRESS,
})
.example(translations.i18n.t('init_no_dir_example_command'), translations.i18n.t('init_example_no_dir'))
.example(translations.i18n.t('init_with_dir_example_command'), translations.i18n.t('init_example_with_dir'));
Expand Down
1 change: 0 additions & 1 deletion src/engine/commands/project/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default {
workspaceName: chalk.green(workspace.name),
environment: chalk.green(environmentName),
endpoint: chalk.green(`${workspace.apiHost}/${workspaceId}`),
region: workspace.region,
}),
);
},
Expand Down
1 change: 0 additions & 1 deletion src/interfaces/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ export interface RequestOptions {
export interface Workspace {
readonly id: string;
readonly name: string;
readonly region: string;
readonly apiHost: string;
}
4 changes: 3 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
project_info_usage: 'COMMAND\n 8base project info\n\nDESCRIPTION\n Display the info about current project.',
project_info_describe: 'Display the info about current project.',
project_info_text:
'Workspace Id: {{-workspaceId}}\nWorkspace Name: {{-workspaceName}}\nEnvironment: {{-environment}}\nregion: {{-region}}\nAPI Endpoint: {{-endpoint}}',
'Workspace Id: {{-workspaceId}}\nWorkspace Name: {{-workspaceName}}\nEnvironment: {{-environment}}\nAPI Endpoint: {{-endpoint}}',
project_info_cant_find_workspace:
"Can't find workspace with {{-workspaceId}} identifier. Looks like you are using a various account or project workspace was deleted.",

Expand Down Expand Up @@ -105,6 +105,8 @@ export default {
configure_select_workspace: 'Select workspace for current project',
configure_prevent_select_workspace: 'Workspace selection canceled',

configure_error: "Please configure first by running '8base configure'",

/**
* Init related messages
*/
Expand Down

0 comments on commit 18f6398

Please sign in to comment.