@apollo-annotation/cli 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +28 -28
  2. package/dist/ApolloConf.d.ts +22 -0
  3. package/dist/ApolloConf.js +143 -0
  4. package/dist/baseCommand.js +3 -14
  5. package/dist/commands/assembly/add-fasta.js +16 -26
  6. package/dist/commands/assembly/add-gff.js +11 -23
  7. package/dist/commands/assembly/check.js +7 -18
  8. package/dist/commands/assembly/delete.js +1 -1
  9. package/dist/commands/assembly/sequence.js +3 -11
  10. package/dist/commands/config.js +20 -52
  11. package/dist/commands/feature/add-child.js +10 -16
  12. package/dist/commands/feature/copy.js +13 -22
  13. package/dist/commands/feature/delete.js +7 -16
  14. package/dist/commands/feature/edit-attribute.js +3 -4
  15. package/dist/commands/feature/edit-coords.js +8 -11
  16. package/dist/commands/feature/edit-type.js +4 -3
  17. package/dist/commands/feature/edit.js +3 -15
  18. package/dist/commands/feature/get.js +6 -17
  19. package/dist/commands/feature/import.js +6 -12
  20. package/dist/commands/login.js +16 -28
  21. package/dist/commands/logout.js +4 -13
  22. package/dist/commands/status.js +4 -12
  23. package/dist/utils.d.ts +2 -2
  24. package/dist/utils.js +8 -14
  25. package/oclif.manifest.json +57 -57
  26. package/package.json +2 -1
  27. package/dist/Config.d.ts +0 -43
  28. package/dist/Config.js +0 -233
  29. package/dist/commands/config.test.d.ts +0 -1
  30. package/dist/commands/config.test.js +0 -188
  31. package/dist/commands/login.test.d.ts +0 -1
  32. package/dist/commands/login.test.js +0 -52
  33. package/dist/commands/logout.test.d.ts +0 -1
  34. package/dist/commands/logout.test.js +0 -67
  35. package/dist/commands/status.test.d.ts +0 -1
  36. package/dist/commands/status.test.js +0 -54
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from 'node:events';
2
2
  import { Response } from 'undici';
3
- import { Config } from './Config.js';
3
+ import { ApolloConf } from './ApolloConf.js';
4
4
  export declare const CLI_SERVER_ADDRESS = "http://127.0.0.1:5657";
5
5
  export declare const CLI_SERVER_ADDRESS_CALLBACK = "http://127.0.0.1:5657/auth/callback";
6
6
  export declare class CheckError extends Error {
@@ -10,7 +10,7 @@ export interface UserCredentials {
10
10
  }
11
11
  export declare function createFetchErrorMessage(response: Response, additionalText?: string): Promise<string>;
12
12
  export declare function checkConfigfileExists(configFile: string): void;
13
- export declare function checkProfileExists(profileName: string, config: Config): void;
13
+ export declare function checkProfileExists(profileName: string, config: ApolloConf): void;
14
14
  export declare function basicCheckConfig(configFile: string, profileName: string): void;
15
15
  /**
16
16
  * @deprecated Use this function while we wait to resolve the TypeError when using localhost in fetch.
package/dist/utils.js CHANGED
@@ -8,7 +8,7 @@ import * as fs from 'node:fs';
8
8
  import * as os from 'node:os';
9
9
  import * as path from 'node:path';
10
10
  import { Agent, FormData, Response, fetch } from 'undici';
11
- import { Config, ConfigError } from './Config.js';
11
+ import { ApolloConf, ConfigError } from './ApolloConf.js';
12
12
  const CONFIG_PATH = path.resolve(os.homedir(), '.clirc');
13
13
  export const CLI_SERVER_ADDRESS = 'http://127.0.0.1:5657';
14
14
  export const CLI_SERVER_ADDRESS_CALLBACK = `${CLI_SERVER_ADDRESS}/auth/callback`;
@@ -37,7 +37,7 @@ export function checkProfileExists(profileName, config) {
37
37
  }
38
38
  export function basicCheckConfig(configFile, profileName) {
39
39
  checkConfigfileExists(configFile);
40
- const config = new Config(configFile);
40
+ const config = new ApolloConf(configFile);
41
41
  checkProfileExists(profileName, config);
42
42
  }
43
43
  /**
@@ -307,19 +307,13 @@ export async function uploadFile(address, accessToken, file, type) {
307
307
  }),
308
308
  };
309
309
  const url = new URL(localhostToAddress(`${address}/files`));
310
- try {
311
- const response = await fetch(url, auth);
312
- if (!response.ok) {
313
- const errorMessage = await createFetchErrorMessage(response, 'uploadFile failed');
314
- throw new ConfigError(errorMessage);
315
- }
316
- const json = (await response.json());
317
- return json['_id'];
318
- }
319
- catch (error) {
320
- console.error(error);
321
- throw error;
310
+ const response = await fetch(url, auth);
311
+ if (!response.ok) {
312
+ const errorMessage = await createFetchErrorMessage(response, 'uploadFile failed');
313
+ throw new ConfigError(errorMessage);
322
314
  }
315
+ const json = (await response.json());
316
+ return json['_id'];
323
317
  }
324
318
  /* Wrap text to max `length` per line */
325
319
  export function wrapLines(s, length) {
@@ -395,7 +395,7 @@
395
395
  "assembly:check": {
396
396
  "aliases": [],
397
397
  "args": {},
398
- "description": "Manage checks, i.e. the rules ensuring features in an assembly are plausible.\nThis command only sets the check to apply, to retrieve features flagged by these\nchecks use `apollo feature check`.",
398
+ "description": "Manage checks, i.e. the rules ensuring features in an assembly are plausible.\nThis command only sets the checks to apply, to retrieve features flagged by\nthese checks use `apollo feature check`.",
399
399
  "examples": [
400
400
  {
401
401
  "description": "View available check types:",
@@ -699,61 +699,6 @@
699
699
  "get.js"
700
700
  ]
701
701
  },
702
- "refseq:get": {
703
- "aliases": [],
704
- "args": {},
705
- "description": "Output the reference sequences in one or more assemblies in json format. This\ncommand returns the sequence characteristics (e.g., name, ID, etc), not the DNA\nsequences. Use `assembly sequence` for that.",
706
- "examples": [
707
- {
708
- "description": "All sequences in the database:",
709
- "command": "<%= config.bin %> <%= command.id %>"
710
- },
711
- {
712
- "description": "Only sequences for these assemblies:",
713
- "command": "<%= config.bin %> <%= command.id %> -a mm9 mm10"
714
- }
715
- ],
716
- "flags": {
717
- "profile": {
718
- "description": "Use credentials from this profile",
719
- "name": "profile",
720
- "hasDynamicHelp": false,
721
- "multiple": false,
722
- "type": "option"
723
- },
724
- "config-file": {
725
- "description": "Use this config file (mostly for testing)",
726
- "name": "config-file",
727
- "hasDynamicHelp": false,
728
- "multiple": false,
729
- "type": "option"
730
- },
731
- "assembly": {
732
- "char": "a",
733
- "description": "Get reference sequences for these assembly names or IDs; use - to read it from stdin",
734
- "name": "assembly",
735
- "hasDynamicHelp": false,
736
- "multiple": true,
737
- "type": "option"
738
- }
739
- },
740
- "hasDynamicHelp": false,
741
- "hiddenAliases": [],
742
- "id": "refseq:get",
743
- "pluginAlias": "@apollo-annotation/cli",
744
- "pluginName": "@apollo-annotation/cli",
745
- "pluginType": "core",
746
- "strict": true,
747
- "summary": "Get reference sequences",
748
- "enableJsonFlag": false,
749
- "isESM": true,
750
- "relativePath": [
751
- "dist",
752
- "commands",
753
- "refseq",
754
- "get.js"
755
- ]
756
- },
757
702
  "feature:add-child": {
758
703
  "aliases": [],
759
704
  "args": {},
@@ -1560,6 +1505,61 @@
1560
1505
  "search.js"
1561
1506
  ]
1562
1507
  },
1508
+ "refseq:get": {
1509
+ "aliases": [],
1510
+ "args": {},
1511
+ "description": "Output the reference sequences in one or more assemblies in json format. This\ncommand returns the sequence characteristics (e.g., name, ID, etc), not the DNA\nsequences. Use `assembly sequence` for that.",
1512
+ "examples": [
1513
+ {
1514
+ "description": "All sequences in the database:",
1515
+ "command": "<%= config.bin %> <%= command.id %>"
1516
+ },
1517
+ {
1518
+ "description": "Only sequences for these assemblies:",
1519
+ "command": "<%= config.bin %> <%= command.id %> -a mm9 mm10"
1520
+ }
1521
+ ],
1522
+ "flags": {
1523
+ "profile": {
1524
+ "description": "Use credentials from this profile",
1525
+ "name": "profile",
1526
+ "hasDynamicHelp": false,
1527
+ "multiple": false,
1528
+ "type": "option"
1529
+ },
1530
+ "config-file": {
1531
+ "description": "Use this config file (mostly for testing)",
1532
+ "name": "config-file",
1533
+ "hasDynamicHelp": false,
1534
+ "multiple": false,
1535
+ "type": "option"
1536
+ },
1537
+ "assembly": {
1538
+ "char": "a",
1539
+ "description": "Get reference sequences for these assembly names or IDs; use - to read it from stdin",
1540
+ "name": "assembly",
1541
+ "hasDynamicHelp": false,
1542
+ "multiple": true,
1543
+ "type": "option"
1544
+ }
1545
+ },
1546
+ "hasDynamicHelp": false,
1547
+ "hiddenAliases": [],
1548
+ "id": "refseq:get",
1549
+ "pluginAlias": "@apollo-annotation/cli",
1550
+ "pluginName": "@apollo-annotation/cli",
1551
+ "pluginType": "core",
1552
+ "strict": true,
1553
+ "summary": "Get reference sequences",
1554
+ "enableJsonFlag": false,
1555
+ "isESM": true,
1556
+ "relativePath": [
1557
+ "dist",
1558
+ "commands",
1559
+ "refseq",
1560
+ "get.js"
1561
+ ]
1562
+ },
1563
1563
  "user:get": {
1564
1564
  "aliases": [],
1565
1565
  "args": {},
@@ -1628,5 +1628,5 @@
1628
1628
  ]
1629
1629
  }
1630
1630
  },
1631
- "version": "0.1.17"
1631
+ "version": "0.1.18"
1632
1632
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@apollo-annotation/cli",
3
3
  "description": "Command line interface for the Apollo annotation server",
4
- "version": "0.1.17",
4
+ "version": "0.1.18",
5
5
  "author": "Apollo Team",
6
6
  "repository": {
7
7
  "type": "git",
@@ -41,6 +41,7 @@
41
41
  "@oclif/core": "^3.18.2",
42
42
  "@oclif/plugin-help": "^6.0.8",
43
43
  "bson": "^6.3.0",
44
+ "conf": "^12.0.0",
44
45
  "joi": "^17.7.0",
45
46
  "open": "^10.1.0",
46
47
  "tslib": "^2.3.1",
package/dist/Config.d.ts DELETED
@@ -1,43 +0,0 @@
1
- import Joi from 'joi';
2
- export declare class ConfigError extends Error {
3
- }
4
- interface BaseProfile {
5
- address: string;
6
- accessType: 'google' | 'microsoft' | 'guest';
7
- accessToken: string;
8
- }
9
- interface RootProfile extends Omit<BaseProfile, 'accessType'> {
10
- accessType: 'root';
11
- rootCredentials: {
12
- username: string;
13
- password: string;
14
- };
15
- }
16
- export type Profile = BaseProfile | RootProfile;
17
- export declare enum KEYS {
18
- address = "address",
19
- accessType = "accessType",
20
- accessToken = "accessToken",
21
- rootCredentials_username = "rootCredentials.username",
22
- rootCredentials_password = "rootCredentials.password"
23
- }
24
- export declare function optionDesc(): string[];
25
- export declare class Config {
26
- private configFile;
27
- private profiles;
28
- constructor(configFile: string);
29
- private index;
30
- private addProps;
31
- private checkKey;
32
- get(key: string, profileName: string): string;
33
- set(key: string, value: string, profileName: string): void;
34
- writeConfigFile(): void;
35
- getProfileNames(): string[];
36
- validate(): Joi.ValidationResult;
37
- getAccess(profileName: string): Promise<{
38
- address: string;
39
- accessToken: string;
40
- }>;
41
- toString(): string;
42
- }
43
- export {};
package/dist/Config.js DELETED
@@ -1,233 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
2
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
- /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
4
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
5
- /* eslint-disable @typescript-eslint/no-unnecessary-condition */
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import Joi from 'joi';
9
- import YAML, { YAMLParseError } from 'yaml';
10
- import { checkProfileExists, queryApollo } from './utils.js';
11
- export class ConfigError extends Error {
12
- }
13
- export var KEYS;
14
- (function (KEYS) {
15
- KEYS["address"] = "address";
16
- KEYS["accessType"] = "accessType";
17
- KEYS["accessToken"] = "accessToken";
18
- KEYS["rootCredentials_username"] = "rootCredentials.username";
19
- KEYS["rootCredentials_password"] = "rootCredentials.password";
20
- })(KEYS || (KEYS = {}));
21
- function optionDocs() {
22
- const docs = [];
23
- for (const v of Object.values(KEYS)) {
24
- switch (v) {
25
- case 'address': {
26
- docs.push({
27
- key: v,
28
- description: 'Address and port e.g http://localhost:3999',
29
- });
30
- break;
31
- }
32
- case 'accessType': {
33
- docs.push({
34
- key: v,
35
- description: 'How to access Apollo. accessType is typically one of: google, microsoft, guest, root. Allowed types depend on your Apollo setup',
36
- });
37
- break;
38
- }
39
- case 'accessToken': {
40
- docs.push({
41
- key: v,
42
- description: 'Access token. Usually inserted by `apollo login`',
43
- });
44
- break;
45
- }
46
- case 'rootCredentials.username': {
47
- docs.push({
48
- key: v,
49
- description: 'Username of root account. Only set this for "root" access type',
50
- });
51
- break;
52
- }
53
- case 'rootCredentials.password': {
54
- docs.push({
55
- key: v,
56
- description: 'Password for root account. Only set this for "root" access type',
57
- });
58
- break;
59
- }
60
- default: {
61
- throw new ConfigError(`Unexpected key: ${v}`);
62
- }
63
- }
64
- }
65
- return docs;
66
- }
67
- export function optionDesc() {
68
- const docs = [];
69
- for (const x of optionDocs()) {
70
- docs.push(`- ${x.key}:\n${x.description}`);
71
- }
72
- return docs;
73
- }
74
- function isValidAddress(address) {
75
- // const port: string | undefined = address.split(':').pop()
76
- // if (port === undefined || /^\d+$/.test(port) === false) {
77
- // return false
78
- // }
79
- let url;
80
- try {
81
- url = new URL(address);
82
- }
83
- catch {
84
- return false;
85
- }
86
- if (url.protocol !== 'http:' && url.protocol !== 'https:') {
87
- return false;
88
- }
89
- return true;
90
- }
91
- const profileSchema = Joi.object({
92
- address: Joi.string()
93
- .uri({ scheme: /https?/ })
94
- .required(),
95
- accessType: Joi.string()
96
- .valid('google', 'microsoft', 'root', 'guest')
97
- .required(),
98
- accessToken: Joi.string(),
99
- rootCredentials: Joi.object({
100
- username: Joi.string().required(),
101
- password: Joi.string().required(),
102
- }).when('accessType', {
103
- is: Joi.string().valid('root'),
104
- // eslint-disable-next-line unicorn/no-thenable
105
- then: Joi.required(),
106
- otherwise: Joi.forbidden(),
107
- }),
108
- });
109
- const configSchema = Joi.object().pattern(Joi.string(), profileSchema);
110
- export class Config {
111
- configFile;
112
- profiles = {};
113
- constructor(configFile) {
114
- this.configFile = configFile;
115
- if (fs.existsSync(configFile)) {
116
- const data = fs.readFileSync(configFile, 'utf8').trim();
117
- if (data !== '') {
118
- let config;
119
- try {
120
- config = YAML.parse(data);
121
- }
122
- catch (error) {
123
- if (error instanceof YAMLParseError) {
124
- process.stderr.write('Error: Configuration file is probably invalid yaml format:\n');
125
- process.stderr.write(error.message);
126
- }
127
- else if (error instanceof Error) {
128
- process.stderr.write('Unexpected error:');
129
- process.stderr.write(error.message);
130
- }
131
- // eslint-disable-next-line unicorn/no-process-exit
132
- process.exit(1);
133
- }
134
- this.profiles = config;
135
- }
136
- }
137
- }
138
- index(obj, arr, value) {
139
- if (typeof arr == 'string') {
140
- return this.index(obj, arr.split('.'), value);
141
- }
142
- if (arr.length == 1 && value !== undefined) {
143
- return (obj[arr[0]] = value);
144
- }
145
- if (arr.length === 0) {
146
- return obj;
147
- }
148
- return this.index(obj[arr[0]], arr.slice(1), value);
149
- }
150
- addProps(obj, arr, value) {
151
- // credit https://stackoverflow.com/questions/17643965/how-to-automatically-add-properties-to-an-object-that-is-undefined
152
- if (typeof arr == 'string') {
153
- arr = arr.split('.');
154
- }
155
- obj[arr[0]] = obj[arr[0]] || {};
156
- const tmpObj = obj[arr[0]];
157
- if (arr.length > 1) {
158
- arr.shift();
159
- this.addProps(tmpObj, arr, value);
160
- }
161
- else if (value !== undefined) {
162
- obj[arr[0]] = value;
163
- }
164
- return obj;
165
- }
166
- checkKey(key) {
167
- for (const x of Object.values(KEYS)) {
168
- if (x === key) {
169
- return;
170
- }
171
- }
172
- throw new ConfigError(`Invalid configuration key: "${key}". Valid keys are:\n${Object.values('\n')}`);
173
- }
174
- get(key, profileName) {
175
- this.checkKey(key);
176
- const profile = this.profiles[profileName];
177
- if (!profile) {
178
- // throw new Error(`No profile name "${profileName}" found`)
179
- return '';
180
- }
181
- this.addProps(profile, key);
182
- const value = this.index(profile, key);
183
- if (typeof value === 'object' && Object.keys(value).length === 0) {
184
- // The key is valid but missing from config
185
- return '';
186
- }
187
- return value;
188
- }
189
- set(key, value, profileName) {
190
- this.checkKey(key);
191
- if (key === KEYS[KEYS.address] && !isValidAddress(value)) {
192
- throw new ConfigError(`"${value}" is not a valid value for "${key}"`);
193
- }
194
- const profile = this.profiles[profileName] ?? {};
195
- this.profiles[profileName] = profile;
196
- this.addProps(profile, key, value);
197
- }
198
- writeConfigFile() {
199
- let APOLLO_DISABLE_CONFIG_CREATE = false;
200
- if (process.env.APOLLO_DISABLE_CONFIG_CREATE !== undefined &&
201
- process.env.APOLLO_DISABLE_CONFIG_CREATE !== '0') {
202
- APOLLO_DISABLE_CONFIG_CREATE = true;
203
- }
204
- if (APOLLO_DISABLE_CONFIG_CREATE && !fs.existsSync(this.configFile)) {
205
- throw new ConfigError('Configuration file does not exist yet, please create it as an empty file first.');
206
- }
207
- const yml = YAML.stringify(this.profiles);
208
- fs.mkdirSync(path.dirname(this.configFile), { recursive: true });
209
- fs.writeFileSync(this.configFile, yml);
210
- }
211
- getProfileNames() {
212
- return Object.keys(this.profiles);
213
- }
214
- validate() {
215
- return configSchema.validate(this.profiles);
216
- }
217
- async getAccess(profileName) {
218
- checkProfileExists(profileName, this);
219
- const address = this.get('address', profileName);
220
- if (address === undefined || address.trim() === '') {
221
- throw new ConfigError(`Profile "${profileName}" has no address. Please run "apollo config" to set it up.`);
222
- }
223
- const accessToken = this.get('accessToken', profileName);
224
- if (accessToken === undefined || accessToken.trim() === '') {
225
- throw new ConfigError(`Profile "${profileName}" has no access token. Please run "apollo login" to set it up.`);
226
- }
227
- await queryApollo(address, accessToken, 'assemblies');
228
- return { address, accessToken };
229
- }
230
- toString() {
231
- return YAML.stringify(this.profiles);
232
- }
233
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,188 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
- import fs from 'node:fs';
4
- import { dirname } from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
- import { expect, test } from '@oclif/test';
7
- import YAML from 'yaml';
8
- import { CONFIG_FILE, TEST_DATA_DIR, VERBOSE, copyFile, } from '../test/fixtures.js';
9
- const __dirname = fileURLToPath(new URL('.', import.meta.url));
10
- describe('apollo config: Query config file', () => {
11
- before(() => {
12
- copyFile(`${TEST_DATA_DIR}/complete_config.yaml`, CONFIG_FILE, VERBOSE);
13
- });
14
- after(() => {
15
- fs.rmSync(CONFIG_FILE);
16
- });
17
- let cmd = ['config', 'rootCredentials.password'];
18
- test
19
- .stdout()
20
- .command(cmd, { root: dirname(dirname(__dirname)) })
21
- .it(cmd.join(' '), (ctx) => {
22
- expect(ctx.stdout.trim()).to.equal('1234');
23
- });
24
- cmd = ['config', 'address'];
25
- test
26
- .stdout()
27
- .command(cmd, { root: dirname(dirname(__dirname)) })
28
- .it(cmd.join(' '), (ctx) => {
29
- expect(ctx.stdout.trim()).to.equal('http://localhost:3999');
30
- });
31
- cmd = ['config', 'someInvalidKey'];
32
- test
33
- .stderr()
34
- .command(cmd, { root: dirname(dirname(__dirname)) })
35
- .exit(1)
36
- .do((output) => expect(output.stderr).to.contain('someInvalidKey'))
37
- .it(cmd.join(' '));
38
- cmd = ['config', '--profile', 'profile1', 'address'];
39
- test
40
- .stdout()
41
- .command(cmd, { root: dirname(dirname(__dirname)) })
42
- .it(cmd.join(' '), (ctx) => {
43
- expect(ctx.stdout.trim()).to.equal('http://localhost:1999');
44
- });
45
- cmd = ['config', '--profile', 'profile1', 'rootCredentials.username'];
46
- test
47
- .stdout()
48
- .command(cmd, { root: dirname(dirname(__dirname)) })
49
- .it(cmd.join(' '), (ctx) => {
50
- expect(ctx.stdout.trim()).to.equal('');
51
- });
52
- cmd = ['config', '--profile', 'nonExistantProfile', 'address'];
53
- test
54
- .stdout()
55
- .command(cmd, { root: dirname(dirname(__dirname)) })
56
- .it(cmd.join(' '), (ctx) => {
57
- expect(ctx.stdout.trim()).to.equal('');
58
- });
59
- });
60
- describe('apollo config: Missing config file', () => {
61
- let cmd = ['config', 'rootCredentials.password'];
62
- test
63
- .stdout()
64
- .command(cmd, { root: dirname(dirname(__dirname)) })
65
- .it(cmd.join(' '), (ctx) => {
66
- expect(ctx.stdout.trim()).to.equal('');
67
- });
68
- cmd = ['config', 'address'];
69
- test
70
- .stdout()
71
- .command(cmd, { root: dirname(dirname(__dirname)) })
72
- .it(cmd.join(' '), (ctx) => {
73
- expect(ctx.stdout.trim()).to.equal('');
74
- });
75
- });
76
- describe('apollo config: Create config directory', () => {
77
- const outdir = `${TEST_DATA_DIR}/_tmp`;
78
- before(() => {
79
- fs.rmSync(outdir, { recursive: true, force: true });
80
- });
81
- after(() => {
82
- fs.rmSync(outdir, { recursive: true, force: true });
83
- });
84
- const cmd = [
85
- 'config',
86
- '--config-file',
87
- `${outdir}/config.yaml`,
88
- 'address',
89
- 'http://localhost:3999',
90
- ];
91
- test
92
- .stdout()
93
- .command(cmd, { root: dirname(dirname(__dirname)) })
94
- .it(cmd.join(' '), () => {
95
- expect(fs.existsSync(`${outdir}/config.yaml`));
96
- });
97
- });
98
- describe('apollo config: Read & edit config file', () => {
99
- before(() => {
100
- copyFile(`${TEST_DATA_DIR}/complete_config.yaml`, CONFIG_FILE, VERBOSE);
101
- });
102
- after(() => {
103
- fs.rmSync(CONFIG_FILE);
104
- });
105
- let cmd = ['config', 'address', 'http://localhost:4321'];
106
- test
107
- .stdout()
108
- .command(cmd, { root: dirname(dirname(__dirname)) })
109
- .it(cmd.join(' '), () => {
110
- const cfg = YAML.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
111
- expect(cfg.default.address).to.equal('http://localhost:4321');
112
- expect(cfg.default.rootCredentials.username).to.equal('root');
113
- });
114
- cmd = ['config', 'rootCredentials.username', 'root2'];
115
- test
116
- .stdout()
117
- .command(cmd, { root: dirname(dirname(__dirname)) })
118
- .it(cmd.join(' '), () => {
119
- const cfg = YAML.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
120
- expect(cfg.default.rootCredentials.username).to.equal('root2');
121
- });
122
- cmd = ['config', 'accessType', 'microsoft'];
123
- test
124
- .stdout()
125
- .command(cmd, { root: dirname(dirname(__dirname)) })
126
- .it(cmd.join(' '), () => {
127
- const cfg = YAML.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
128
- expect(cfg.default.accessType).to.equal('microsoft');
129
- });
130
- });
131
- describe('Do not set invalid address', () => {
132
- before(() => {
133
- copyFile(`${TEST_DATA_DIR}/complete_config.yaml`, CONFIG_FILE, VERBOSE);
134
- });
135
- after(() => {
136
- fs.rmSync(CONFIG_FILE);
137
- });
138
- const cmd = ['config', 'address', 'http://localhost:3999xxx'];
139
- test
140
- .stderr()
141
- .command(cmd, { root: dirname(dirname(__dirname)) })
142
- .exit(1)
143
- .do((output) => expect(output.stderr).to.contain('http://localhost:3999xxx'))
144
- .it(cmd.join(' '));
145
- });
146
- describe('apollo config: Write config file from scratch', () => {
147
- after(() => {
148
- fs.rmSync(CONFIG_FILE);
149
- });
150
- let cmd = ['config', 'rootCredentials.username', 'somename'];
151
- test
152
- .stdout()
153
- .command(cmd, { root: dirname(dirname(__dirname)) })
154
- .it(cmd.join(' '), () => {
155
- const cfg = YAML.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
156
- expect(cfg.default.rootCredentials.username).to.equal('somename');
157
- });
158
- cmd = [
159
- 'config',
160
- '--profile',
161
- 'myProfile',
162
- 'rootCredentials.password',
163
- 'somepwd',
164
- ];
165
- test
166
- .stdout()
167
- .command(cmd, { root: dirname(dirname(__dirname)) })
168
- .it(cmd.join(' '), () => {
169
- const cfg = YAML.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
170
- expect(cfg.myProfile.rootCredentials.password).to.equal('somepwd');
171
- });
172
- });
173
- describe('apollo config: Handle strings as numbers in yaml', () => {
174
- const cmd = [
175
- 'config',
176
- '--config-file',
177
- 'test_data/nameAsNumber.yaml',
178
- 'rootCredentials.username',
179
- ];
180
- test
181
- .stderr()
182
- .stdout()
183
- .command(cmd, { root: dirname(dirname(__dirname)) })
184
- .do((output) => expect(output.stderr).contains('must be a string'))
185
- .it(cmd.join(' '), (ctx) => {
186
- expect(ctx.stdout.trim()).to.equal('7890');
187
- });
188
- });
@@ -1 +0,0 @@
1
- export {};