From 37cfc7e016a7ce912fd734761c252e84b721bfb9 Mon Sep 17 00:00:00 2001 From: Garrett Stevens Date: Thu, 19 Sep 2024 21:05:50 +0000 Subject: [PATCH 1/9] Simplify getAccess --- packages/apollo-cli/src/baseCommand.ts | 10 +++------- packages/apollo-cli/src/commands/assembly/add-fasta.ts | 3 +-- packages/apollo-cli/src/commands/assembly/add-gff.ts | 3 +-- packages/apollo-cli/src/commands/assembly/check.ts | 3 +-- packages/apollo-cli/src/commands/assembly/delete.ts | 3 +-- packages/apollo-cli/src/commands/assembly/get.ts | 3 +-- packages/apollo-cli/src/commands/assembly/sequence.ts | 3 +-- packages/apollo-cli/src/commands/change/get.ts | 3 +-- packages/apollo-cli/src/commands/feature/add-child.ts | 3 +-- packages/apollo-cli/src/commands/feature/check.ts | 3 +-- packages/apollo-cli/src/commands/feature/copy.ts | 3 +-- packages/apollo-cli/src/commands/feature/delete.ts | 3 +-- .../apollo-cli/src/commands/feature/edit-attribute.ts | 3 +-- .../apollo-cli/src/commands/feature/edit-coords.ts | 3 +-- packages/apollo-cli/src/commands/feature/edit-type.ts | 3 +-- packages/apollo-cli/src/commands/feature/edit.ts | 3 +-- packages/apollo-cli/src/commands/feature/get-id.ts | 3 +-- packages/apollo-cli/src/commands/feature/get.ts | 3 +-- packages/apollo-cli/src/commands/feature/import.ts | 3 +-- packages/apollo-cli/src/commands/feature/search.ts | 3 +-- packages/apollo-cli/src/commands/jbrowse/get-config.ts | 5 +---- packages/apollo-cli/src/commands/jbrowse/set-config.ts | 5 ++--- packages/apollo-cli/src/commands/refseq/add-alias.ts | 3 +-- packages/apollo-cli/src/commands/refseq/get.ts | 3 +-- packages/apollo-cli/src/commands/user/get.ts | 3 +-- 25 files changed, 28 insertions(+), 58 deletions(-) diff --git a/packages/apollo-cli/src/baseCommand.ts b/packages/apollo-cli/src/baseCommand.ts index ec3bdcf0b..6c2727543 100644 --- a/packages/apollo-cli/src/baseCommand.ts +++ b/packages/apollo-cli/src/baseCommand.ts @@ -43,15 +43,11 @@ export abstract class BaseCommand extends Command { return config } - public async getAccess( - configFile: string | undefined, - profileName: string | undefined, - ): Promise<{ address: string; accessToken: string }> { + public async getAccess(): Promise<{ address: string; accessToken: string }> { + const { 'config-file': configFile, profile } = this.flags const config: ApolloConf = this.getConfig(configFile) - if (profileName === undefined) { - profileName = process.env.APOLLO_PROFILE ?? 'default' - } + const profileName = process.env.APOLLO_PROFILE ?? profile ?? 'default' return config.getAccess(profileName) } diff --git a/packages/apollo-cli/src/commands/assembly/add-fasta.ts b/packages/apollo-cli/src/commands/assembly/add-fasta.ts index 1c62edd96..4937982cc 100644 --- a/packages/apollo-cli/src/commands/assembly/add-fasta.ts +++ b/packages/apollo-cli/src/commands/assembly/add-fasta.ts @@ -55,8 +55,7 @@ export default class Get extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Get) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const assemblyName = flags.assembly ?? path.basename(flags['input-file']) diff --git a/packages/apollo-cli/src/commands/assembly/add-gff.ts b/packages/apollo-cli/src/commands/assembly/add-gff.ts index febdca9f4..ad968bd4d 100644 --- a/packages/apollo-cli/src/commands/assembly/add-gff.ts +++ b/packages/apollo-cli/src/commands/assembly/add-gff.ts @@ -58,8 +58,7 @@ export default class AddGff extends BaseCommand { this.error(`File ${flags['input-file']} does not exist`) } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const fileId = await uploadFile( access.address, diff --git a/packages/apollo-cli/src/commands/assembly/check.ts b/packages/apollo-cli/src/commands/assembly/check.ts index e4ef3da53..ae1525858 100644 --- a/packages/apollo-cli/src/commands/assembly/check.ts +++ b/packages/apollo-cli/src/commands/assembly/check.ts @@ -129,8 +129,7 @@ export default class Check extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Check) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const checkTypes: object[] = await getCheckTypes( access.address, diff --git a/packages/apollo-cli/src/commands/assembly/delete.ts b/packages/apollo-cli/src/commands/assembly/delete.ts index 1cc9586ac..faeb40a1e 100644 --- a/packages/apollo-cli/src/commands/assembly/delete.ts +++ b/packages/apollo-cli/src/commands/assembly/delete.ts @@ -36,8 +36,7 @@ export default class Delete extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Delete) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const assembly: string[] = idReader(flags.assembly) const deleteIds = await convertAssemblyNameToId( diff --git a/packages/apollo-cli/src/commands/assembly/get.ts b/packages/apollo-cli/src/commands/assembly/get.ts index cdcc497bc..8d39cbce1 100644 --- a/packages/apollo-cli/src/commands/assembly/get.ts +++ b/packages/apollo-cli/src/commands/assembly/get.ts @@ -26,8 +26,7 @@ export default class Get extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Get) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const assemblies: Response = await queryApollo( access.address, diff --git a/packages/apollo-cli/src/commands/assembly/sequence.ts b/packages/apollo-cli/src/commands/assembly/sequence.ts index ad9f5d948..5c2c22225 100644 --- a/packages/apollo-cli/src/commands/assembly/sequence.ts +++ b/packages/apollo-cli/src/commands/assembly/sequence.ts @@ -93,8 +93,7 @@ export default class ApolloCmd extends BaseCommand { this.error('Start and end coordinates must be greater than 0.') } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() let assembly = undefined if (flags.assembly !== undefined) { diff --git a/packages/apollo-cli/src/commands/change/get.ts b/packages/apollo-cli/src/commands/change/get.ts index 41d17a02a..e83380896 100644 --- a/packages/apollo-cli/src/commands/change/get.ts +++ b/packages/apollo-cli/src/commands/change/get.ts @@ -30,8 +30,7 @@ export default class Get extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Get) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const changes: Response = await queryApollo( access.address, diff --git a/packages/apollo-cli/src/commands/feature/add-child.ts b/packages/apollo-cli/src/commands/feature/add-child.ts index 9abdd0046..58527ffc1 100644 --- a/packages/apollo-cli/src/commands/feature/add-child.ts +++ b/packages/apollo-cli/src/commands/feature/add-child.ts @@ -72,8 +72,7 @@ export default class Get extends BaseCommand { } const [featureId] = ff - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const res: Response = await getFeatureById( access.address, diff --git a/packages/apollo-cli/src/commands/feature/check.ts b/packages/apollo-cli/src/commands/feature/check.ts index 4257b9932..55b4c6d13 100644 --- a/packages/apollo-cli/src/commands/feature/check.ts +++ b/packages/apollo-cli/src/commands/feature/check.ts @@ -48,8 +48,7 @@ export default class Check extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Check) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() let keepFeatures = new Set() if (flags['feature-id'] !== undefined) { diff --git a/packages/apollo-cli/src/commands/feature/copy.ts b/packages/apollo-cli/src/commands/feature/copy.ts index f7c3b2379..072d1e7ec 100644 --- a/packages/apollo-cli/src/commands/feature/copy.ts +++ b/packages/apollo-cli/src/commands/feature/copy.ts @@ -60,8 +60,7 @@ export default class Copy extends BaseCommand { this.error('Start coordinate must be greater than 0') } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const res: Response = await getFeatureById( access.address, diff --git a/packages/apollo-cli/src/commands/feature/delete.ts b/packages/apollo-cli/src/commands/feature/delete.ts index 612f7ed8e..9cbdc38bc 100644 --- a/packages/apollo-cli/src/commands/feature/delete.ts +++ b/packages/apollo-cli/src/commands/feature/delete.ts @@ -82,8 +82,7 @@ export default class Delete extends BaseCommand { featureIds.add(x) } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() for (const featureId of featureIds) { const res: Response = await getFeatureById( diff --git a/packages/apollo-cli/src/commands/feature/edit-attribute.ts b/packages/apollo-cli/src/commands/feature/edit-attribute.ts index fbdd0dd8a..442e1acbd 100644 --- a/packages/apollo-cli/src/commands/feature/edit-attribute.ts +++ b/packages/apollo-cli/src/commands/feature/edit-attribute.ts @@ -72,8 +72,7 @@ export default class EditAttibute extends BaseCommand { } const [featureId] = ff - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const response: Response = await getFeatureById( access.address, diff --git a/packages/apollo-cli/src/commands/feature/edit-coords.ts b/packages/apollo-cli/src/commands/feature/edit-coords.ts index 9f8f5102a..9cf32ca46 100644 --- a/packages/apollo-cli/src/commands/feature/edit-coords.ts +++ b/packages/apollo-cli/src/commands/feature/edit-coords.ts @@ -82,8 +82,7 @@ export default class Get extends BaseCommand { } const [featureId] = ff - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const res: Response = await getFeatureById( access.address, diff --git a/packages/apollo-cli/src/commands/feature/edit-type.ts b/packages/apollo-cli/src/commands/feature/edit-type.ts index 733b2a183..8f595c445 100644 --- a/packages/apollo-cli/src/commands/feature/edit-type.ts +++ b/packages/apollo-cli/src/commands/feature/edit-type.ts @@ -42,8 +42,7 @@ export default class Get extends BaseCommand { } const [featureId] = ff - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const response: Response = await getFeatureById( access.address, diff --git a/packages/apollo-cli/src/commands/feature/edit.ts b/packages/apollo-cli/src/commands/feature/edit.ts index 1ed7880f3..686be8c52 100644 --- a/packages/apollo-cli/src/commands/feature/edit.ts +++ b/packages/apollo-cli/src/commands/feature/edit.ts @@ -61,8 +61,7 @@ export default class Get extends BaseCommand { json = [json] } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() for (const change of json) { const str = JSON.stringify(change) diff --git a/packages/apollo-cli/src/commands/feature/get-id.ts b/packages/apollo-cli/src/commands/feature/get-id.ts index 5c226a67b..9ca6c19d0 100644 --- a/packages/apollo-cli/src/commands/feature/get-id.ts +++ b/packages/apollo-cli/src/commands/feature/get-id.ts @@ -37,8 +37,7 @@ export default class Get extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Get) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() let ids = idReader(flags['feature-id']) ids = [...new Set(ids)] diff --git a/packages/apollo-cli/src/commands/feature/get.ts b/packages/apollo-cli/src/commands/feature/get.ts index 38783fca7..d7905f298 100644 --- a/packages/apollo-cli/src/commands/feature/get.ts +++ b/packages/apollo-cli/src/commands/feature/get.ts @@ -55,8 +55,7 @@ export default class Get extends BaseCommand { this.error('Start and end coordinates must be greater than 0.') } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const refseqIds: string[] = await getRefseqId( access.address, diff --git a/packages/apollo-cli/src/commands/feature/import.ts b/packages/apollo-cli/src/commands/feature/import.ts index bf7e570f1..a5182e3e1 100644 --- a/packages/apollo-cli/src/commands/feature/import.ts +++ b/packages/apollo-cli/src/commands/feature/import.ts @@ -49,8 +49,7 @@ export default class Import extends BaseCommand { this.error(`File "${flags['input-file']}" does not exist`) } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const assembly = await convertAssemblyNameToId( access.address, diff --git a/packages/apollo-cli/src/commands/feature/search.ts b/packages/apollo-cli/src/commands/feature/search.ts index c7ab586a9..7f021a125 100644 --- a/packages/apollo-cli/src/commands/feature/search.ts +++ b/packages/apollo-cli/src/commands/feature/search.ts @@ -96,8 +96,7 @@ export default class Search extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Search) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() let assemblyIds: string[] = [] if (flags.assembly === undefined) { diff --git a/packages/apollo-cli/src/commands/jbrowse/get-config.ts b/packages/apollo-cli/src/commands/jbrowse/get-config.ts index 2fd4e70f1..5411f6fd2 100644 --- a/packages/apollo-cli/src/commands/jbrowse/get-config.ts +++ b/packages/apollo-cli/src/commands/jbrowse/get-config.ts @@ -15,10 +15,7 @@ export default class GetConfig extends BaseCommand { ] public async run(): Promise { - const { flags } = await this.parse(GetConfig) - - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const response = await queryApollo( access.address, diff --git a/packages/apollo-cli/src/commands/jbrowse/set-config.ts b/packages/apollo-cli/src/commands/jbrowse/set-config.ts index 8539ee42c..e78964f82 100644 --- a/packages/apollo-cli/src/commands/jbrowse/set-config.ts +++ b/packages/apollo-cli/src/commands/jbrowse/set-config.ts @@ -34,14 +34,13 @@ export default class SetConfig extends BaseCommand { } async run(): Promise { - const { args, flags } = await this.parse(SetConfig) + const { args } = await this.parse(SetConfig) if (!fs.existsSync(args.inputFile)) { this.error(`File ${args.inputFile} does not exist`) } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const filehandle = await fs.promises.open(args.inputFile) const fileContent = await filehandle.readFile({ encoding: 'utf8' }) await filehandle.close() diff --git a/packages/apollo-cli/src/commands/refseq/add-alias.ts b/packages/apollo-cli/src/commands/refseq/add-alias.ts index ddbea2ca7..433eb5ace 100644 --- a/packages/apollo-cli/src/commands/refseq/add-alias.ts +++ b/packages/apollo-cli/src/commands/refseq/add-alias.ts @@ -47,8 +47,7 @@ export default class AddRefNameAlias extends BaseCommand< this.error(`File ${flags['input-file']} does not exist`) } - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const filehandle = await fs.promises.open(flags['input-file']) const fileContent = await filehandle.readFile({ encoding: 'utf8' }) await filehandle.close() diff --git a/packages/apollo-cli/src/commands/refseq/get.ts b/packages/apollo-cli/src/commands/refseq/get.ts index 09585be53..75746b287 100644 --- a/packages/apollo-cli/src/commands/refseq/get.ts +++ b/packages/apollo-cli/src/commands/refseq/get.ts @@ -40,8 +40,7 @@ export default class Get extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Get) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const refSeqs: Response = await queryApollo( access.address, diff --git a/packages/apollo-cli/src/commands/user/get.ts b/packages/apollo-cli/src/commands/user/get.ts index e9b993a10..552241524 100644 --- a/packages/apollo-cli/src/commands/user/get.ts +++ b/packages/apollo-cli/src/commands/user/get.ts @@ -40,8 +40,7 @@ export default class Get extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Get) - const access: { address: string; accessToken: string } = - await this.getAccess(flags['config-file'], flags.profile) + const access = await this.getAccess() const users: Response = await queryApollo( access.address, From ff88bb4ce2bfb2ab63d073ddcde38b083cce8724 Mon Sep 17 00:00:00 2001 From: Garrett Stevens Date: Thu, 19 Sep 2024 21:20:00 +0000 Subject: [PATCH 2/9] Fix some CLI lint errors --- .../apollo-cli/src/commands/assembly/check.ts | 13 ++---- packages/apollo-cli/src/utils.ts | 40 ++++++++----------- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/packages/apollo-cli/src/commands/assembly/check.ts b/packages/apollo-cli/src/commands/assembly/check.ts index ae1525858..e4fe72837 100644 --- a/packages/apollo-cli/src/commands/assembly/check.ts +++ b/packages/apollo-cli/src/commands/assembly/check.ts @@ -151,10 +151,6 @@ export default class Check extends BaseCommand { asm[0], ) - if (Object.keys(assembly).length === 0) { - this.error(`Assembly ${flags.assembly} not found`) - } - const currentChecks: object[] = getCheckTypesForAssembly( checkTypes, assembly, @@ -191,11 +187,8 @@ export default class Check extends BaseCommand { } } - await setChecks( - access.address, - access.accessToken, - assembly['_id' as keyof typeof assembly], - [...newChecks.values()], - ) + await setChecks(access.address, access.accessToken, assembly._id, [ + ...newChecks.values(), + ]) } } diff --git a/packages/apollo-cli/src/utils.ts b/packages/apollo-cli/src/utils.ts index 8dc514399..c84a3da8f 100644 --- a/packages/apollo-cli/src/utils.ts +++ b/packages/apollo-cli/src/utils.ts @@ -1,8 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unnecessary-condition */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ import * as crypto from 'node:crypto' import EventEmitter from 'node:events' import * as fs from 'node:fs' @@ -119,25 +114,23 @@ export async function getAssembly( address: string, accessToken: string, assemblyNameOrId: string, -): Promise { +): Promise { const assemblyId: string[] = await convertAssemblyNameToId( address, accessToken, [assemblyNameOrId], ) if (assemblyId.length === 0) { - return {} + throw new Error(`Assembly "${assemblyNameOrId}" not found`) } const res: Response = await queryApollo(address, accessToken, 'assemblies') const assemblies = (await res.json()) as ApolloAssemblySnapshot[] - let assemblyObj = {} for (const x of assemblies) { if (x._id === assemblyId[0]) { - assemblyObj = JSON.parse(JSON.stringify(x)) - break + return JSON.parse(JSON.stringify(x)) as ApolloAssemblySnapshot } } - return assemblyObj + throw new Error(`Assembly "${assemblyNameOrId}" not found`) } export async function getRefseqId( @@ -195,7 +188,7 @@ export async function getRefseqId( async function checkNameToIdDict( address: string, accessToken: string, -): Promise> { +): Promise> { const asm = await queryApollo(address, accessToken, 'checks/types') const ja = (await asm.json()) as CheckResultSnapshot[] // Not sure if CheckResultSnapshot is the right interface const nameToId: Record = {} @@ -228,7 +221,7 @@ export async function convertCheckNameToId( export async function assemblyNameToIdDict( address: string, accessToken: string, -): Promise> { +): Promise> { const asm = await queryApollo(address, accessToken, 'assemblies') const ja = (await asm.json()) as object[] const nameToId: Record = {} @@ -522,25 +515,26 @@ export function wrapLines(s: string, length?: number): string { } export function idReader(input: string[], removeDuplicates = true): string[] { - let ids = [] + let ids: string[] = [] for (const xin of input) { - let data + let data: string if (xin == '-') { - data = fs.readFileSync('/dev/stdin').toString() + data = fs.readFileSync(process.stdin.fd, 'utf8') } else if (fs.existsSync(xin)) { data = fs.readFileSync(xin).toString() } else { data = xin } try { - data = JSON.parse(data) - if (data.length === undefined) { - data = [data] + let parsedData = JSON.parse(data) as + | Record + | [Record] + if (!Array.isArray(parsedData)) { + parsedData = [parsedData] } - for (const x of data) { - const id = x['_id' as keyof typeof x] - if (id !== undefined) { - ids.push(id) + for (const x of parsedData) { + if ('_id' in x && typeof x._id === 'string') { + ids.push(x._id) } } } catch { From cd827738624edd4db90321093b04d7c340ca47cc Mon Sep 17 00:00:00 2001 From: Garrett Stevens Date: Thu, 19 Sep 2024 23:09:24 +0000 Subject: [PATCH 3/9] Read stdin async instead of sync --- .../apollo-cli/src/commands/assembly/check.ts | 2 +- .../apollo-cli/src/commands/assembly/delete.ts | 2 +- packages/apollo-cli/src/commands/assembly/get.ts | 2 +- .../apollo-cli/src/commands/assembly/sequence.ts | 2 +- packages/apollo-cli/src/commands/change/get.ts | 2 +- .../apollo-cli/src/commands/feature/add-child.ts | 2 +- .../apollo-cli/src/commands/feature/check.ts | 4 ++-- .../apollo-cli/src/commands/feature/delete.ts | 2 +- .../src/commands/feature/edit-attribute.ts | 2 +- .../src/commands/feature/edit-coords.ts | 2 +- .../apollo-cli/src/commands/feature/edit-type.ts | 2 +- .../apollo-cli/src/commands/feature/get-id.ts | 2 +- .../apollo-cli/src/commands/feature/search.ts | 2 +- packages/apollo-cli/src/commands/refseq/get.ts | 2 +- packages/apollo-cli/src/utils.ts | 16 ++++++++++++++-- 15 files changed, 29 insertions(+), 17 deletions(-) diff --git a/packages/apollo-cli/src/commands/assembly/check.ts b/packages/apollo-cli/src/commands/assembly/check.ts index e4fe72837..0fa724f85 100644 --- a/packages/apollo-cli/src/commands/assembly/check.ts +++ b/packages/apollo-cli/src/commands/assembly/check.ts @@ -144,7 +144,7 @@ export default class Check extends BaseCommand { this.error('Please specify the assembly to manage for checks') } - const asm: string[] = idReader([flags.assembly]) + const asm: string[] = await idReader([flags.assembly]) const assembly = await getAssembly( access.address, access.accessToken, diff --git a/packages/apollo-cli/src/commands/assembly/delete.ts b/packages/apollo-cli/src/commands/assembly/delete.ts index faeb40a1e..9eea55a6c 100644 --- a/packages/apollo-cli/src/commands/assembly/delete.ts +++ b/packages/apollo-cli/src/commands/assembly/delete.ts @@ -38,7 +38,7 @@ export default class Delete extends BaseCommand { const access = await this.getAccess() - const assembly: string[] = idReader(flags.assembly) + const assembly: string[] = await idReader(flags.assembly) const deleteIds = await convertAssemblyNameToId( access.address, access.accessToken, diff --git a/packages/apollo-cli/src/commands/assembly/get.ts b/packages/apollo-cli/src/commands/assembly/get.ts index 8d39cbce1..7c50184a2 100644 --- a/packages/apollo-cli/src/commands/assembly/get.ts +++ b/packages/apollo-cli/src/commands/assembly/get.ts @@ -36,7 +36,7 @@ export default class Get extends BaseCommand { let assemblyIds: string[] = [] if (flags.assembly !== undefined) { - const assembly = idReader(flags.assembly) + const assembly = await idReader(flags.assembly) assemblyIds = await convertAssemblyNameToId( access.address, access.accessToken, diff --git a/packages/apollo-cli/src/commands/assembly/sequence.ts b/packages/apollo-cli/src/commands/assembly/sequence.ts index 5c2c22225..4825006e3 100644 --- a/packages/apollo-cli/src/commands/assembly/sequence.ts +++ b/packages/apollo-cli/src/commands/assembly/sequence.ts @@ -97,7 +97,7 @@ export default class ApolloCmd extends BaseCommand { let assembly = undefined if (flags.assembly !== undefined) { - ;[assembly] = idReader([flags.assembly]) + ;[assembly] = await idReader([flags.assembly]) } let refseqIds: string[] = [] diff --git a/packages/apollo-cli/src/commands/change/get.ts b/packages/apollo-cli/src/commands/change/get.ts index e83380896..6872d665c 100644 --- a/packages/apollo-cli/src/commands/change/get.ts +++ b/packages/apollo-cli/src/commands/change/get.ts @@ -42,7 +42,7 @@ export default class Get extends BaseCommand { let keep = json if (flags.assembly !== undefined) { keep = [] - const assembly = idReader(flags.assembly) + const assembly = await idReader(flags.assembly) const assemblyIds = await convertAssemblyNameToId( access.address, access.accessToken, diff --git a/packages/apollo-cli/src/commands/feature/add-child.ts b/packages/apollo-cli/src/commands/feature/add-child.ts index 58527ffc1..a21c7629b 100644 --- a/packages/apollo-cli/src/commands/feature/add-child.ts +++ b/packages/apollo-cli/src/commands/feature/add-child.ts @@ -66,7 +66,7 @@ export default class Get extends BaseCommand { this.error('Coordinates must be greater than 0') } - const ff = idReader([flags['feature-id']]) + const ff = await idReader([flags['feature-id']]) if (ff.length !== 1) { this.error(`Expected only one feature identifier. Got ${ff.length}`) } diff --git a/packages/apollo-cli/src/commands/feature/check.ts b/packages/apollo-cli/src/commands/feature/check.ts index 55b4c6d13..5fc7a46bb 100644 --- a/packages/apollo-cli/src/commands/feature/check.ts +++ b/packages/apollo-cli/src/commands/feature/check.ts @@ -52,7 +52,7 @@ export default class Check extends BaseCommand { let keepFeatures = new Set() if (flags['feature-id'] !== undefined) { - keepFeatures = new Set(idReader(flags['feature-id'])) + keepFeatures = new Set(await idReader(flags['feature-id'])) } const keepAsmId: string[] = await keepAssemblies( @@ -108,7 +108,7 @@ async function keepAssemblies( keepAssembly.push(x._id) } } else { - const ids = idReader([assembly]) + const ids = await idReader([assembly]) keepAssembly = await convertAssemblyNameToId(address, accessToken, ids) } return keepAssembly diff --git a/packages/apollo-cli/src/commands/feature/delete.ts b/packages/apollo-cli/src/commands/feature/delete.ts index 9cbdc38bc..514f24f06 100644 --- a/packages/apollo-cli/src/commands/feature/delete.ts +++ b/packages/apollo-cli/src/commands/feature/delete.ts @@ -76,7 +76,7 @@ export default class Delete extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Delete) - const tmpIds = idReader(flags['feature-id']) + const tmpIds = await idReader(flags['feature-id']) const featureIds = new Set() for (const x of tmpIds) { featureIds.add(x) diff --git a/packages/apollo-cli/src/commands/feature/edit-attribute.ts b/packages/apollo-cli/src/commands/feature/edit-attribute.ts index 442e1acbd..be106aac4 100644 --- a/packages/apollo-cli/src/commands/feature/edit-attribute.ts +++ b/packages/apollo-cli/src/commands/feature/edit-attribute.ts @@ -66,7 +66,7 @@ export default class EditAttibute extends BaseCommand { this.error('Error: Options --delete and --value are mutually exclusive') } - const ff = idReader([flags['feature-id']]) + const ff = await idReader([flags['feature-id']]) if (ff.length !== 1) { this.error(`Expected only one feature identifier. Got ${ff.length}`) } diff --git a/packages/apollo-cli/src/commands/feature/edit-coords.ts b/packages/apollo-cli/src/commands/feature/edit-coords.ts index 9cf32ca46..e1345b149 100644 --- a/packages/apollo-cli/src/commands/feature/edit-coords.ts +++ b/packages/apollo-cli/src/commands/feature/edit-coords.ts @@ -76,7 +76,7 @@ export default class Get extends BaseCommand { flags.start -= 1 } - const ff = idReader([flags['feature-id']]) + const ff = await idReader([flags['feature-id']]) if (ff.length !== 1) { this.error(`Expected only one feature identifier. Got ${ff.length}`) } diff --git a/packages/apollo-cli/src/commands/feature/edit-type.ts b/packages/apollo-cli/src/commands/feature/edit-type.ts index 8f595c445..b918936a0 100644 --- a/packages/apollo-cli/src/commands/feature/edit-type.ts +++ b/packages/apollo-cli/src/commands/feature/edit-type.ts @@ -36,7 +36,7 @@ export default class Get extends BaseCommand { public async run(): Promise { const { flags } = await this.parse(Get) - const ff = idReader([flags['feature-id']]) + const ff = await idReader([flags['feature-id']]) if (ff.length !== 1) { this.error(`Expected only one feature identifier. Got ${ff.length}`) } diff --git a/packages/apollo-cli/src/commands/feature/get-id.ts b/packages/apollo-cli/src/commands/feature/get-id.ts index 9ca6c19d0..756a8f6a2 100644 --- a/packages/apollo-cli/src/commands/feature/get-id.ts +++ b/packages/apollo-cli/src/commands/feature/get-id.ts @@ -39,7 +39,7 @@ export default class Get extends BaseCommand { const access = await this.getAccess() - let ids = idReader(flags['feature-id']) + let ids = await idReader(flags['feature-id']) ids = [...new Set(ids)] const results: object[] = [] diff --git a/packages/apollo-cli/src/commands/feature/search.ts b/packages/apollo-cli/src/commands/feature/search.ts index 7f021a125..8b25d1c80 100644 --- a/packages/apollo-cli/src/commands/feature/search.ts +++ b/packages/apollo-cli/src/commands/feature/search.ts @@ -109,7 +109,7 @@ export default class Search extends BaseCommand { assemblyIds.push(x._id) } } else { - const assembly = idReader(flags.assembly) + const assembly = await idReader(flags.assembly) assemblyIds = await convertAssemblyNameToId( access.address, access.accessToken, diff --git a/packages/apollo-cli/src/commands/refseq/get.ts b/packages/apollo-cli/src/commands/refseq/get.ts index 75746b287..0c18f9263 100644 --- a/packages/apollo-cli/src/commands/refseq/get.ts +++ b/packages/apollo-cli/src/commands/refseq/get.ts @@ -52,7 +52,7 @@ export default class Get extends BaseCommand { let keep = json if (flags.assembly !== undefined) { keep = [] - const assembly = idReader(flags.assembly) + const assembly = await idReader(flags.assembly) const assemblyIds = await convertAssemblyNameToId( access.address, access.accessToken, diff --git a/packages/apollo-cli/src/utils.ts b/packages/apollo-cli/src/utils.ts index c84a3da8f..62f41178c 100644 --- a/packages/apollo-cli/src/utils.ts +++ b/packages/apollo-cli/src/utils.ts @@ -3,6 +3,7 @@ import EventEmitter from 'node:events' import * as fs from 'node:fs' import * as os from 'node:os' import * as path from 'node:path' +import { stdin } from 'node:process' import { Transform, TransformCallback, @@ -514,12 +515,23 @@ export function wrapLines(s: string, length?: number): string { return wr } -export function idReader(input: string[], removeDuplicates = true): string[] { +async function readStdin() { + const chunks: Buffer[] = [] + for await (const chunk of stdin) { + chunks.push(Buffer.from(chunk as Buffer)) + } + return Buffer.concat(chunks).toString('utf8') +} + +export async function idReader( + input: string[], + removeDuplicates = true, +): Promise { let ids: string[] = [] for (const xin of input) { let data: string if (xin == '-') { - data = fs.readFileSync(process.stdin.fd, 'utf8') + data = await readStdin() } else if (fs.existsSync(xin)) { data = fs.readFileSync(xin).toString() } else { From 28c2d3370356a0cf4caae644c80b1a9750d98fc5 Mon Sep 17 00:00:00 2001 From: Garrett Stevens Date: Fri, 20 Sep 2024 02:01:04 +0000 Subject: [PATCH 4/9] Restore README --- .husky/pre-commit.js | 10 +- packages/apollo-cli/README.md | 1005 ++++++++++++++++++++++++++++++++- 2 files changed, 990 insertions(+), 25 deletions(-) diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js index 895ebd950..06ed20e05 100644 --- a/.husky/pre-commit.js +++ b/.husky/pre-commit.js @@ -26,11 +26,6 @@ function main() { spawn.sync('yarn', ['workspace', '@apollo-annotation/cli', 'build'], { stdio: 'inherit', }) - spawn.sync( - 'yarn', - ['workspace', '@apollo-annotation/cli', 'oclif', 'readme'], - { stdio: 'inherit' }, - ) spawn.sync( 'yarn', [ @@ -44,6 +39,11 @@ function main() { ], { stdio: 'inherit' }, ) + spawn.sync( + 'yarn', + ['workspace', '@apollo-annotation/cli', 'oclif', 'readme'], + { stdio: 'inherit' }, + ) spawn.sync( 'git', [ diff --git a/packages/apollo-cli/README.md b/packages/apollo-cli/README.md index 18e3ea991..499503018 100644 --- a/packages/apollo-cli/README.md +++ b/packages/apollo-cli/README.md @@ -5,7 +5,6 @@ - [Table of contents](#table-of-contents) - [Usage](#usage) - [Commands](#commands) -- [Command Topics](#command-topics) # Usage @@ -30,24 +29,990 @@ USAGE -# Command Topics - -- [`apollo assembly`](../website/docs/cli//assembly.md) - Commands to handle - assemblies -- [`apollo change`](../website/docs/cli//change.md) - Commands to handle the log - of changes made to the database -- [`apollo config`](../website/docs/cli//config.md) - Get or set apollo - configuration options -- [`apollo feature`](../website/docs/cli//feature.md) - Commands to handle - features -- [`apollo help`](../website/docs/cli//help.md) - Display help for apollo. -- [`apollo jbrowse`](../website/docs/cli//jbrowse.md) - Commands to manage the - JBrowse configuration -- [`apollo login`](../website/docs/cli//login.md) - Login to Apollo -- [`apollo logout`](../website/docs/cli//logout.md) - Logout of Apollo -- [`apollo refseq`](../website/docs/cli//refseq.md) - Commands to handle - reference sequences -- [`apollo status`](../website/docs/cli//status.md) - View authentication status -- [`apollo user`](../website/docs/cli//user.md) - Commands to handle users +- [`apollo assembly add-fasta`](#apollo-assembly-add-fasta) +- [`apollo assembly add-gff`](#apollo-assembly-add-gff) +- [`apollo assembly check`](#apollo-assembly-check) +- [`apollo assembly delete`](#apollo-assembly-delete) +- [`apollo assembly get`](#apollo-assembly-get) +- [`apollo assembly sequence`](#apollo-assembly-sequence) +- [`apollo change get`](#apollo-change-get) +- [`apollo config [KEY] [VALUE]`](#apollo-config-key-value) +- [`apollo feature add-child`](#apollo-feature-add-child) +- [`apollo feature check`](#apollo-feature-check) +- [`apollo feature copy`](#apollo-feature-copy) +- [`apollo feature delete`](#apollo-feature-delete) +- [`apollo feature edit`](#apollo-feature-edit) +- [`apollo feature edit-attribute`](#apollo-feature-edit-attribute) +- [`apollo feature edit-coords`](#apollo-feature-edit-coords) +- [`apollo feature edit-type`](#apollo-feature-edit-type) +- [`apollo feature get`](#apollo-feature-get) +- [`apollo feature get-id`](#apollo-feature-get-id) +- [`apollo feature import`](#apollo-feature-import) +- [`apollo feature search`](#apollo-feature-search) +- [`apollo help [COMMANDS]`](#apollo-help-commands) +- [`apollo jbrowse get-config`](#apollo-jbrowse-get-config) +- [`apollo jbrowse set-config INPUTFILE`](#apollo-jbrowse-set-config-inputfile) +- [`apollo login`](#apollo-login) +- [`apollo logout`](#apollo-logout) +- [`apollo refseq add-alias`](#apollo-refseq-add-alias) +- [`apollo refseq get`](#apollo-refseq-get) +- [`apollo status`](#apollo-status) +- [`apollo user get`](#apollo-user-get) + +## `apollo assembly add-fasta` + +Add new assembly from local or external fasta file + +``` +USAGE + $ apollo assembly add-fasta -i [--profile ] [--config-file ] [-a ] [-x ] [-f] + +FLAGS + -a, --assembly= Name for this assembly. Use the file name if omitted + -f, --force Delete existing assembly, if it exists + -i, --input-file= (required) Input fasta file + -x, --index= URL of the index. Required if input is an external source and ignored if input is a local + file + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Add new assembly from local or external fasta file + +EXAMPLES + From local file: + + $ apollo assembly add-fasta -i genome.fa -a myAssembly + + From external source we also need the URL of the index: + + $ apollo assembly add-fasta -i https://.../genome.fa -x https://.../genome.fa.fai -a myAssembly +``` + +_See code: +[src/commands/assembly/add-fasta.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/assembly/add-fasta.ts)_ + +## `apollo assembly add-gff` + +Add new assembly from gff or gft file + +``` +USAGE + $ apollo assembly add-gff -i [--profile ] [--config-file ] [-a ] [-o] [-f] + +FLAGS + -a, --assembly= Name for this assembly. Use the file name if omitted + -f, --force Delete existing assembly, if it exists + -i, --input-file= (required) Input gff or gtf file + -o, --omit-features Do not import features, only upload the sequences + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Add new assembly from gff or gft file + + The gff file is expected to contain sequences as per gff specifications. + Features are also imported by default. + +EXAMPLES + Import sequences and features: + + $ apollo assembly add-gff -i genome.gff -a myAssembly + + Import sequences only: + + $ apollo assembly add-gff -i genome.gff -a myAssembly -o +``` + +_See code: +[src/commands/assembly/add-gff.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/assembly/add-gff.ts)_ + +## `apollo assembly check` + +Add, view, or delete checks to assembly + +``` +USAGE + $ apollo assembly check [--profile ] [--config-file ] [-a ] [-c ] [-d] + +FLAGS + -a, --assembly= Manage checks in this assembly + -c, --check=... Add these check names or IDs. If unset, print the checks set for assembly + -d, --delete Delete (instead of adding) checks + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Add, view, or delete checks to assembly + + Manage checks, i.e. the rules ensuring features in an assembly are plausible. + This command only sets the checks to apply, to retrieve features flagged by + these checks use `apollo feature check`. + +EXAMPLES + View available check types: + + $ apollo assembly check + + View checks set for assembly hg19: + + $ apollo assembly check -a hg19 + + Add checks to assembly: + + $ apollo assembly check -a hg19 -c CDSCheck + + Delete checks from assembly: + + $ apollo assembly check -a hg19 -c CDSCheck --delete +``` + +_See code: +[src/commands/assembly/check.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/assembly/check.ts)_ + +## `apollo assembly delete` + +Delete assemblies + +``` +USAGE + $ apollo assembly delete -a [--profile ] [--config-file ] [-v] + +FLAGS + -a, --assembly=... (required) Assembly names or IDs to delete + -v, --verbose Print to stdout the array of assemblies deleted + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Delete assemblies + + Assemblies to delete may be names or IDs + +EXAMPLES + Delete multiple assemblies using name or ID: + + $ apollo assembly delete -a mouse 6605826fbd0eee691f83e73f +``` + +_See code: +[src/commands/assembly/delete.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/assembly/delete.ts)_ + +## `apollo assembly get` + +Get available assemblies + +``` +USAGE + $ apollo assembly get [--profile ] [--config-file ] [-a ] + +FLAGS + -a, --assembly=... Get assemblies in this list of names or IDs + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get available assemblies + + Print to stdout the list of assemblies in json format +``` + +_See code: +[src/commands/assembly/get.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/assembly/get.ts)_ + +## `apollo assembly sequence` + +Get reference sequence in fasta format + +``` +USAGE + $ apollo assembly sequence [--profile ] [--config-file ] [-a ] [-r ] [-s ] [-e + ] + +FLAGS + -a, --assembly= Find input reference sequence in this assembly + -e, --end= End coordinate + -r, --refseq= Reference sequence. If unset, get all sequences + -s, --start= [default: 1] Start coordinate (1-based) + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get reference sequence in fasta format + + Return the reference sequence for a given assembly and coordinates + +EXAMPLES + Get all sequences in myAssembly: + + $ apollo assembly sequence -a myAssembly + + Get sequence in coordinates chr1:1..1000: + + $ apollo assembly sequence -a myAssembly -r chr1 -s 1 -e 1000 +``` + +_See code: +[src/commands/assembly/sequence.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/assembly/sequence.ts)_ + +## `apollo change get` + +Get list of changes + +``` +USAGE + $ apollo change get [--profile ] [--config-file ] [-a ] + +FLAGS + -a, --assembly=... Get changes only for these assembly names or IDs (but see description) + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get list of changes + + Return the change log in json format. Note that when an assembly is deleted the + link between common name and ID is lost (it can still be recovered by inspecting + the change log but at present this task is left to the user). In such cases you + need to use the assembly ID. +``` + +_See code: +[src/commands/change/get.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/change/get.ts)_ + +## `apollo config [KEY] [VALUE]` + +Get or set apollo configuration options + +``` +USAGE + $ apollo config [KEY] [VALUE] [--profile ] [---file ] [--get-config-file] + +ARGUMENTS + KEY Name of configuration parameter + VALUE Parameter value + +FLAGS + --config-file= Use this config file (mostly for testing) + --get-config-file Return the path to the config file and exit (this file may not exist yet) + --profile= Profile to create or edit + +DESCRIPTION + Get or set apollo configuration options + + Use this command to create or edit a user profile with credentials to access + Apollo. Configuration options are: + + - address: + Address and port e.g http://localhost:3999 + + - accessType: + How to access Apollo. accessType is typically one of: google, microsoft, guest, + root. Allowed types depend on your Apollo setup + + - accessToken: + Access token. Usually inserted by `apollo login` + + - rootCredentials.username: + Username of root account. Only set this for "root" access type + + - rootCredentials.password: + Password for root account. Only set this for "root" access type + +EXAMPLES + Interactive setup: + + $ apollo config + + Setup with key/value pairs: + + $ apollo config --profile admin address http://localhost:3999 + + Get current address for default profile: + + $ apollo config address +``` + +_See code: +[src/commands/config.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/config.ts)_ + +## `apollo feature add-child` + +Add a child feature (e.g. add an exon to an mRNA) + +``` +USAGE + $ apollo feature add-child -s -e -t [--profile ] [--config-file ] [-i ] + +FLAGS + -e, --end= (required) End coordinate of the child feature (1-based) + -i, --feature-id= [default: -] Add a child to this feature ID; use - to read it from stdin + -s, --start= (required) Start coordinate of the child feature (1-based) + -t, --type= (required) Type of child feature + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Add a child feature (e.g. add an exon to an mRNA) + + See the other commands under `apollo feature` to retrive the parent ID of + interest and to populate the child feature with attributes. + +EXAMPLES + Add an exon at genomic coordinates 10..20 to this feature ID: + + $ apollo feature add-child -i 6605826fbd0eee691f83e73f -t exon -s 10 -e 20 +``` + +_See code: +[src/commands/feature/add-child.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/add-child.ts)_ + +## `apollo feature check` + +Get check results + +``` +USAGE + $ apollo feature check [--profile ] [--config-file ] [-i ] [-a ] + +FLAGS + -a, --assembly= Get checks for this assembly + -i, --feature-id=... Get checks for these feature identifiers + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get check results + + Use this command to view which features fail checks along with the reason for + failing. Use `apollo assembly check` for managing which checks should be applied + to an assembly + +EXAMPLES + Get all check results in the database: + + $ apollo feature check + + Get check results for assembly hg19: + + $ apollo feature check -a hg19 +``` + +_See code: +[src/commands/feature/check.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/check.ts)_ + +## `apollo feature copy` + +Copy a feature to another location + +``` +USAGE + $ apollo feature copy -r -s [--profile ] [--config-file ] [-i ] [-a ] + +FLAGS + -a, --assembly= Name or ID of target assembly. Not required if refseq is unique in the database + -i, --feature-id= [default: -] Feature ID to copy to; use - to read it from stdin + -r, --refseq= (required) Name or ID of target reference sequence + -s, --start= (required) Start position in target reference sequence + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Copy a feature to another location + + The feature may be copied to the same or to a different assembly. he destination + reference sequence may be selected by name only if unique in the database or by + name and assembly or by identifier. + +EXAMPLES + Copy this feature ID to chr1:100 in assembly hg38: + + $ apollo feature copy -i 6605826fbd0eee691f83e73f -r chr1 -s 100 -a hg38 +``` + +_See code: +[src/commands/feature/copy.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/copy.ts)_ + +## `apollo feature delete` + +Delete one or more features by ID + +``` +USAGE + $ apollo feature delete [--profile ] [--config-file ] [-i ] [-f] [-n] + +FLAGS + -f, --force Ignore non-existing features + -i, --feature-id=... [default: -] Feature IDs to delete + -n, --dry-run Only show what would be delete + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Delete one or more features by ID + + Note that deleting a child feature after deleting its parent will result in an + error unless you set -f/--force. +``` + +_See code: +[src/commands/feature/delete.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/delete.ts)_ + +## `apollo feature edit` + +Edit features using an appropiate json input + +``` +USAGE + $ apollo feature edit [--profile ] [--config-file ] [-j ] + +FLAGS + -j, --json-input= [default: -] Json string or json file or "-" to read json from stdin + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Edit features using an appropiate json input + + Edit a feature by submitting a json input with all the required attributes for + Apollo to process it. This is a very low level command which most users probably + do not need. + + Input may be a json string or a json file and it may be an array of changes. + This is an example input for editing feature type: + + { + "typeName": "TypeChange", + "changedIds": [ + "6613f7d22c957525d631b1cc" + ], + "assembly": "6613f7d1360321540a11e5ed", + "featureId": "6613f7d22c957525d631b1cc", + "oldType": "BAC", + "newType": "G_quartet" + } + +EXAMPLES + Editing by passing a json to stdin: + + echo '{"typeName": ... "newType": "G_quartet"}' | apollo feature edit -j - +``` + +_See code: +[src/commands/feature/edit.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/edit.ts)_ + +## `apollo feature edit-attribute` + +Add, edit, or view a feature attribute + +``` +USAGE + $ apollo feature edit-attribute -a [--profile ] [--config-file ] [-i ] [-v ] [-d] + +FLAGS + -a, --attribute= (required) Attribute key to add or edit + -d, --delete Delete this attribute + -i, --feature-id= [default: -] Feature ID to edit or "-" to read it from stdin + -v, --value=... New attribute value. Separated mutliple values by space to them as a list. If unset return + current value + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Add, edit, or view a feature attribute + + Be aware that there is no checking whether attributes names and values are + valid. For example, you can create non-unique ID attributes or you can set gene + ontology terms to non-existing terms + +EXAMPLES + Add attribute "domains" with a list of values: + + $ apollo feature edit-attribute -i 66...3f -a domains -v ABC PLD + + Print values in "domains" as json array: + + $ apollo feature edit-attribute -i 66...3f -a domains + + Delete attribute "domains" + + $ apollo feature edit-attribute -i 66...3f -a domains -d +``` + +_See code: +[src/commands/feature/edit-attribute.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/edit-attribute.ts)_ + +## `apollo feature edit-coords` + +Edit feature start and/or end coordinates + +``` +USAGE + $ apollo feature edit-coords [--profile ] [--config-file ] [-i ] [-s ] [-e ] + +FLAGS + -e, --end= New end coordinate (1-based) + -i, --feature-id= [default: -] Feature ID to edit or "-" to read it from stdin + -s, --start= New start coordinate (1-based) + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Edit feature start and/or end coordinates + + If editing a child feature that new coordinates must be within the parent's + coordinates. To get the identifier of the feature to edit consider using `apollo + feature get` or `apollo feature search` + +EXAMPLES + Edit start and end: + + $ apollo feature edit-coords -i abc...xyz -s 10 -e 1000 + + Edit end and leave start as it is: + + $ apollo feature edit-coords -i abc...xyz -e 2000 +``` + +_See code: +[src/commands/feature/edit-coords.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/edit-coords.ts)_ + +## `apollo feature edit-type` + +Edit or view feature type + +``` +USAGE + $ apollo feature edit-type [--profile ] [--config-file ] [-i ] [-t ] + +FLAGS + -i, --feature-id= [default: -] Feature ID to edit or "-" to read it from stdin + -t, --type= Assign feature to this type. If unset return the current type + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Edit or view feature type + + Feature type is column 3 in gff format. It must be a valid sequence ontology + term although but the valifdity of the new term is not checked. +``` + +_See code: +[src/commands/feature/edit-type.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/edit-type.ts)_ + +## `apollo feature get` + +Get features in assembly, reference sequence or genomic window + +``` +USAGE + $ apollo feature get [--profile ] [--config-file ] [-a ] [-r ] [-s ] [-e + ] + +FLAGS + -a, --assembly= Find input reference sequence in this assembly + -e, --end= End coordinate + -r, --refseq= Reference sequence. If unset, query all sequences + -s, --start= [default: 1] Start coordinate (1-based) + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get features in assembly, reference sequence or genomic window + +EXAMPLES + Get all features in myAssembly: + + $ apollo feature get -a myAssembly + + Get features intersecting chr1:1..1000. You can omit the assembly name if there + are no other reference sequences named chr1: + + $ apollo feature get -a myAssembly -r chr1 -s 1 -e 1000 +``` + +_See code: +[src/commands/feature/get.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/get.ts)_ + +## `apollo feature get-id` + +Get features given their identifiers + +``` +USAGE + $ apollo feature get-id [--profile ] [--config-file ] [-i ] + +FLAGS + -i, --feature-id=... [default: -] Retrieves feature with these IDs. Use + "-" to read IDs from stdin (one per + line) + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get features given their identifiers + + Invalid identifiers or identifiers not found in the database will be silently + ignored + +EXAMPLES + Get features for these identifiers: + + $ apollo feature get-id -i abc...zyz def...foo +``` + +_See code: +[src/commands/feature/get-id.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/get-id.ts)_ + +## `apollo feature import` + +Import features from local gff file + +``` +USAGE + $ apollo feature import -i -a [--profile ] [--config-file ] [-d] + +FLAGS + -a, --assembly= (required) Import into this assembly name or assembly ID + -d, --delete-existing Delete existing features before importing + -i, --input-file= (required) Input gff or gtf file + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Import features from local gff file + + By default, features are added to the existing ones. + +EXAMPLES + Delete features in myAssembly and then import features.gff3: + + $ apollo feature import -d -i features.gff3 -a myAssembly +``` + +_See code: +[src/commands/feature/import.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/import.ts)_ + +## `apollo feature search` + +Free text search for feature in one or more assemblies + +``` +USAGE + $ apollo feature search -t [--profile ] [--config-file ] [-a ] + +FLAGS + -a, --assembly=... Assembly names or IDs to search; use "-" to read it from stdin. If omitted + search all assemblies + -t, --text= (required) Search for this text query + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Free text search for feature in one or more assemblies + + Return features matching a query string. This command searches only in: + + - Attribute *values* (not attribute names) + - Source field (which in fact is stored as an attribute) + - Feature type + + The search mode is: + + - Case insensitive + - Match only full words, but not necessarily the full value + - Common words are ignored. E.g. "the", "with" + + For example, given this feature: + + chr1 example SNP 10 30 0.987 . . "someKey=Fingerprint BAC with reads" + + Queries "bac" or "mRNA" return the feature. Instead these queries will NOT + match: + + - "someKey" + - "with" + - "Finger" + - "chr1" + - "0.987" + +EXAMPLES + Search "bac" in these assemblies: + + $ apollo feature search -a mm9 mm10 -t bac +``` + +_See code: +[src/commands/feature/search.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/feature/search.ts)_ + +## `apollo help [COMMANDS]` + +Display help for apollo. + +``` +USAGE + $ apollo help [COMMANDS] [-n] + +ARGUMENTS + COMMANDS Command to show help for. + +FLAGS + -n, --nested-commands Include all nested commands in the output. + +DESCRIPTION + Display help for apollo. +``` + +_See code: +[@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.8/src/commands/help.ts)_ + +## `apollo jbrowse get-config` + +Get JBrowse configuration from Apollo + +``` +USAGE + $ apollo jbrowse get-config [--profile ] [--config-file ] + +FLAGS + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get JBrowse configuration from Apollo + + Print to stdout the JBrowse configuration from Apollo in JSON format + +EXAMPLES + Get JBrowse configuration: + + $ apollo jbrowse get-config > config.json +``` + +_See code: +[src/commands/jbrowse/get-config.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/jbrowse/get-config.ts)_ + +## `apollo jbrowse set-config INPUTFILE` + +Set JBrowse configuration + +``` +USAGE + $ apollo jbrowse set-config INPUTFILE [--profile ] [--config-file ] + +ARGUMENTS + INPUTFILE JBrowse configuration file + +FLAGS + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Set JBrowse configuration + + Set JBrowse configuration in Apollo collaboration server + +EXAMPLES + Add JBrowse configuration: + + $ apollo jbrowse set-config config.json +``` + +_See code: +[src/commands/jbrowse/set-config.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/jbrowse/set-config.ts)_ + +## `apollo login` + +Login to Apollo + +``` +USAGE + $ apollo login [--profile ] [--config-file ] [-a ] [-u ] [-p ] [-f] + [--port ] + +FLAGS + -a, --address= Address of Apollo server + -f, --force Force re-authentication even if user is already logged in + -p, --password= Password for + -u, --username= Username for root login + --config-file= Use this config file (mostly for testing) + --port= [default: 3000] Get token by listening to this port number (usually this is >= 1024 and < + 65536) + --profile= Use credentials from this profile + +DESCRIPTION + Login to Apollo + + Use the provided credentials to obtain and save the token to access Apollo. Once + the token for the given profile has been saved in the configuration file, users + do not normally need to execute this command again unless the token has expired. + To setup a new profile use "apollo config" + +EXAMPLES + The most basic and probably most typical usage is to login using the default + profile in configuration file: + + $ apollo login + + Login with a different profile: + + $ apollo login --profile my-profile +``` + +_See code: +[src/commands/login.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/login.ts)_ + +## `apollo logout` + +Logout of Apollo + +``` +USAGE + $ apollo logout [--profile ] [--config-file ] + +FLAGS + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Logout of Apollo + + Logout by removing the access token from the selected profile + +EXAMPLES + Logout default profile: + + $ apollo logout + + Logout selected profile + + $ apollo logout --profile my-profile +``` + +_See code: +[src/commands/logout.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/logout.ts)_ + +## `apollo refseq add-alias` + +Add reference name aliases from a file + +``` +USAGE + $ apollo refseq add-alias -i -a [--profile ] [--config-file ] + +FLAGS + -a, --assembly= (required) Name for this assembly. + -i, --input-file= (required) Input refname alias file + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Add reference name aliases from a file + + Reference name aliasing is a process to make chromosomes that are named slightly + differently but which refer to the same thing render properly. This command + reads a file with reference name aliases and adds them to the database. + +EXAMPLES + Add reference name aliases: + + $ apollo refseq add-alias -i alias.txt -a myAssembly +``` + +_See code: +[src/commands/refseq/add-alias.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/refseq/add-alias.ts)_ + +## `apollo refseq get` + +Get reference sequences + +``` +USAGE + $ apollo refseq get [--profile ] [--config-file ] [-a ] + +FLAGS + -a, --assembly=... Get reference sequences for these assembly names or IDs; use - to read it from stdin + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get reference sequences + + Output the reference sequences in one or more assemblies in json format. This + command returns the sequence characteristics (e.g., name, ID, etc), not the DNA + sequences. Use `assembly sequence` for that. + +EXAMPLES + All sequences in the database: + + $ apollo refseq get + + Only sequences for these assemblies: + + $ apollo refseq get -a mm9 mm10 +``` + +_See code: +[src/commands/refseq/get.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/refseq/get.ts)_ + +## `apollo status` + +View authentication status + +``` +USAGE + $ apollo status [--profile ] [--config-file ] + +FLAGS + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + View authentication status + + This command returns ": Logged in" if the selected profile has an + access token and ": Logged out" otherwise. Note that this command does + not check the validity of the access token. +``` + +_See code: +[src/commands/status.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/status.ts)_ + +## `apollo user get` + +Get list of users + +``` +USAGE + $ apollo user get [--profile ] [--config-file ] [-u ] [-r ] + +FLAGS + -r, --role= Get users with this role + -u, --username= Find this username + --config-file= Use this config file (mostly for testing) + --profile= Use credentials from this profile + +DESCRIPTION + Get list of users + + If set, filters username and role must be both satisfied to return an entry + +EXAMPLES + By username: + + $ apollo user get -u Guest + + By role: + + $ apollo user get -r admin + + Use jq for more control: + + $ apollo user get | jq '.[] | select(.createdAt > "2024-03-18")' +``` + +_See code: +[src/commands/user/get.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/user/get.ts)_ From 6613297dbc1c5696e0f3081e4503767a1e5d48a0 Mon Sep 17 00:00:00 2001 From: dariober Date: Fri, 20 Sep 2024 11:56:05 +0100 Subject: [PATCH 5/9] Use `readStdin()` in edit.ts instead of stdin.fd --- packages/apollo-cli/README.md | 2 +- packages/apollo-cli/src/commands/feature/edit.ts | 3 ++- packages/apollo-cli/src/utils.ts | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/apollo-cli/README.md b/packages/apollo-cli/README.md index 499503018..062837cab 100644 --- a/packages/apollo-cli/README.md +++ b/packages/apollo-cli/README.md @@ -16,7 +16,7 @@ $ npm install -g @apollo-annotation/cli $ apollo COMMAND running command... $ apollo (--version) -@apollo-annotation/cli/0.1.19 linux-x64 node-v20.17.0 +@apollo-annotation/cli/0.1.19 linux-x64 node-v20.13.0 $ apollo --help [COMMAND] USAGE $ apollo COMMAND diff --git a/packages/apollo-cli/src/commands/feature/edit.ts b/packages/apollo-cli/src/commands/feature/edit.ts index 686be8c52..4eef2265f 100644 --- a/packages/apollo-cli/src/commands/feature/edit.ts +++ b/packages/apollo-cli/src/commands/feature/edit.ts @@ -8,6 +8,7 @@ import { BaseCommand } from '../../baseCommand.js' import { createFetchErrorMessage, localhostToAddress, + readStdin, wrapLines, } from '../../utils.js' @@ -51,7 +52,7 @@ export default class Get extends BaseCommand { let jsonStr = flags['json-input'] if (flags['json-input'] === '-') { - jsonStr = fs.readFileSync(process.stdin.fd).toString() + jsonStr = await readStdin() } else if (fs.existsSync(flags['json-input'])) { jsonStr = fs.readFileSync(flags['json-input']).toString() } diff --git a/packages/apollo-cli/src/utils.ts b/packages/apollo-cli/src/utils.ts index 62f41178c..9452ec09b 100644 --- a/packages/apollo-cli/src/utils.ts +++ b/packages/apollo-cli/src/utils.ts @@ -3,7 +3,7 @@ import EventEmitter from 'node:events' import * as fs from 'node:fs' import * as os from 'node:os' import * as path from 'node:path' -import { stdin } from 'node:process' +import { stdin, stderr } from 'node:process' import { Transform, TransformCallback, @@ -248,7 +248,7 @@ export async function convertAssemblyNameToId( } else if (Object.values(nameToId).includes(x)) { ids.push(x) } else if (verbose) { - process.stderr.write(`Warning: Omitting unknown assembly: "${x}"\n`) + stderr.write(`Warning: Omitting unknown assembly: "${x}"\n`) } } if (removeDuplicates) { @@ -515,7 +515,7 @@ export function wrapLines(s: string, length?: number): string { return wr } -async function readStdin() { +export async function readStdin() { const chunks: Buffer[] = [] for await (const chunk of stdin) { chunks.push(Buffer.from(chunk as Buffer)) From 674e4ffb836ba4323cce70131456ba316b2e071f Mon Sep 17 00:00:00 2001 From: dariober Date: Fri, 20 Sep 2024 14:23:30 +0100 Subject: [PATCH 6/9] Simplify checking if user is logged Add test and fix test suite --- packages/apollo-cli/src/commands/login.ts | 28 ++++++++--------------- packages/apollo-cli/src/utils.ts | 10 -------- packages/apollo-cli/test/test.py | 9 +++++++- packages/apollo-cli/test/utils.py | 7 ++++-- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/packages/apollo-cli/src/commands/login.ts b/packages/apollo-cli/src/commands/login.ts index 9727f4689..4ae86227b 100644 --- a/packages/apollo-cli/src/commands/login.ts +++ b/packages/apollo-cli/src/commands/login.ts @@ -10,13 +10,12 @@ import { Errors, Flags, ux } from '@oclif/core' import open from 'open' import { fetch } from 'undici' -import { ApolloConf } from '../ApolloConf.js' +import { ApolloConf, KEYS } from '../ApolloConf.js' import { BaseCommand } from '../baseCommand.js' import { UserCredentials, basicCheckConfig, createFetchErrorMessage, - getUserCredentials, localhostToAddress, waitFor, wrapLines, @@ -96,10 +95,9 @@ export default class Login extends BaseCommand { } let userCredentials: UserCredentials = { accessToken: '' } - try { if (!flags.force) { - await this.checkUserAlreadyLoggedIn() + await this.checkUserAlreadyLoggedIn(config, profileName) } if (accessType === 'root' || flags.username !== undefined) { const username: string = @@ -137,25 +135,19 @@ export default class Login extends BaseCommand { config.set(`${profileName}.accessToken`, userCredentials.accessToken) } - private async checkUserAlreadyLoggedIn() { - const userCredentials = getUserCredentials() - - if (!userCredentials) { - return - } - - const alreadyLoggedIn = ( - Object.keys(userCredentials) as (keyof typeof userCredentials)[] - ).every((key) => Boolean(userCredentials[key])) - - if (!alreadyLoggedIn) { + private async checkUserAlreadyLoggedIn( + userCredentials: ApolloConf, + profileName: string, + ) { + const accessToken: string = userCredentials.get( + `${profileName}.${KEYS.accessToken}`, + ) as string + if (!accessToken) { return } - const reAuthenticate = await ux.confirm( "You're already logged. Do you want to re-authenticate? (y/n)", ) - if (!reAuthenticate) { this.exit(0) } diff --git a/packages/apollo-cli/src/utils.ts b/packages/apollo-cli/src/utils.ts index 9452ec09b..1a49994ca 100644 --- a/packages/apollo-cli/src/utils.ts +++ b/packages/apollo-cli/src/utils.ts @@ -22,7 +22,6 @@ import { CheckResultSnapshot, } from '@apollo-annotation/mst' -const CONFIG_PATH = path.resolve(os.homedir(), '.clirc') export const CLI_SERVER_ADDRESS = 'http://127.0.0.1:5657' export const CLI_SERVER_ADDRESS_CALLBACK = `${CLI_SERVER_ADDRESS}/auth/callback` @@ -324,15 +323,6 @@ export function filterJsonList( return results } -export const getUserCredentials = (): UserCredentials | null => { - try { - const content = fs.readFileSync(CONFIG_PATH, { encoding: 'utf8' }) - return JSON.parse(content) as UserCredentials - } catch { - return null - } -} - export const generatePkceChallenge = (): { state: string codeVerifier: string diff --git a/packages/apollo-cli/test/test.py b/packages/apollo-cli/test/test.py index 56bcc652d..4df6e4fa5 100755 --- a/packages/apollo-cli/test/test.py +++ b/packages/apollo-cli/test/test.py @@ -17,7 +17,7 @@ def setUpModule(): shell(f"{apollo} config {P} accessType root") shell(f"{apollo} config {P} rootCredentials.username admin") shell(f"{apollo} config {P} rootCredentials.password pass") - shell(f"{apollo} login {P}") + shell(f"{apollo} login {P} -f") class TestCLI(unittest.TestCase): @@ -952,6 +952,13 @@ def testRefNameAliasConfiguration(self): all(alias in refname_aliases.get("ctgC", []) for alias in ["ctgc", "CTGC"]) ) + def testLogin(self): + # This should wait for user's input + p = shell(f"{apollo} login {P}", timeout=5, strict=False) + self.assertTrue("Timeout" in p.stderr) # NB: "Timeout" comes from utils.py, not Apollo + # This should be ok + shell(f"{apollo} login {P} --force", timeout=5, strict=True) + if __name__ == "__main__": unittest.main() diff --git a/packages/apollo-cli/test/utils.py b/packages/apollo-cli/test/utils.py index f6ab22630..c45910f59 100644 --- a/packages/apollo-cli/test/utils.py +++ b/packages/apollo-cli/test/utils.py @@ -17,8 +17,11 @@ def __init__(self, cmd, strict=True, timeout=None): stdout, stderr = p.communicate(timeout=timeout) except subprocess.TimeoutExpired: p.kill() - sys.stderr.write(f"Error: Timeout after {timeout} seconds\n") - stdout, stderr = p.communicate() + stderr = f"Error: Timeout after {timeout} seconds\n".encode() + p.wait() + p.stdout.close() + p.stderr.close() + stdout = b'' self.returncode = p.returncode self.stdout = stdout.decode() self.stderr = stderr.decode() From c4f014dde39a4eb0d8f2d2549d17e6e81a388cf0 Mon Sep 17 00:00:00 2001 From: dariober Date: Fri, 20 Sep 2024 14:26:08 +0100 Subject: [PATCH 7/9] Fix format --- packages/apollo-cli/src/utils.ts | 1 - packages/apollo-cli/test/test.py | 4 +++- packages/apollo-cli/test/utils.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/apollo-cli/src/utils.ts b/packages/apollo-cli/src/utils.ts index 1a49994ca..059b0f8c9 100644 --- a/packages/apollo-cli/src/utils.ts +++ b/packages/apollo-cli/src/utils.ts @@ -1,7 +1,6 @@ import * as crypto from 'node:crypto' import EventEmitter from 'node:events' import * as fs from 'node:fs' -import * as os from 'node:os' import * as path from 'node:path' import { stdin, stderr } from 'node:process' import { diff --git a/packages/apollo-cli/test/test.py b/packages/apollo-cli/test/test.py index 4df6e4fa5..fe8cdea65 100755 --- a/packages/apollo-cli/test/test.py +++ b/packages/apollo-cli/test/test.py @@ -955,7 +955,9 @@ def testRefNameAliasConfiguration(self): def testLogin(self): # This should wait for user's input p = shell(f"{apollo} login {P}", timeout=5, strict=False) - self.assertTrue("Timeout" in p.stderr) # NB: "Timeout" comes from utils.py, not Apollo + self.assertTrue( + "Timeout" in p.stderr + ) # NB: "Timeout" comes from utils.py, not Apollo # This should be ok shell(f"{apollo} login {P} --force", timeout=5, strict=True) diff --git a/packages/apollo-cli/test/utils.py b/packages/apollo-cli/test/utils.py index c45910f59..2aca75cbb 100644 --- a/packages/apollo-cli/test/utils.py +++ b/packages/apollo-cli/test/utils.py @@ -21,7 +21,7 @@ def __init__(self, cmd, strict=True, timeout=None): p.wait() p.stdout.close() p.stderr.close() - stdout = b'' + stdout = b"" self.returncode = p.returncode self.stdout = stdout.decode() self.stderr = stderr.decode() From 723e5f840b143fd8880e88c1268b4b9fac7edd47 Mon Sep 17 00:00:00 2001 From: dariober Date: Fri, 20 Sep 2024 15:48:39 +0100 Subject: [PATCH 8/9] Test skipped as it works locally but fails on github (to be investigated) --- packages/apollo-cli/test/test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/apollo-cli/test/test.py b/packages/apollo-cli/test/test.py index fe8cdea65..0744b5f84 100755 --- a/packages/apollo-cli/test/test.py +++ b/packages/apollo-cli/test/test.py @@ -952,6 +952,7 @@ def testRefNameAliasConfiguration(self): all(alias in refname_aliases.get("ctgC", []) for alias in ["ctgc", "CTGC"]) ) + @unittest.skip("Works locally but fails on github") def testLogin(self): # This should wait for user's input p = shell(f"{apollo} login {P}", timeout=5, strict=False) From 5983d9625c4a08994bda74452d0282f7eb94600c Mon Sep 17 00:00:00 2001 From: Garrett Stevens Date: Fri, 20 Sep 2024 17:29:41 +0000 Subject: [PATCH 9/9] Update return code in test --- packages/apollo-cli/test/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apollo-cli/test/test.py b/packages/apollo-cli/test/test.py index 0744b5f84..7dbb50357 100755 --- a/packages/apollo-cli/test/test.py +++ b/packages/apollo-cli/test/test.py @@ -779,7 +779,7 @@ def testAssemblyChecks(self): # Test non-existant assembly p = shell(f"{apollo} assembly check {P} -a non-existant", strict=False) - self.assertEqual(p.returncode, 2) + self.assertEqual(p.returncode, 1) self.assertTrue("non-existant" in p.stderr) # Test non-existant check