Skip to content

Commit

Permalink
jbrowse config cli
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankbrgowda committed Sep 9, 2024
1 parent 60b512e commit 3da532b
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/apollo-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $ npm install -g @apollo-annotation/cli
$ apollo COMMAND
running command...
$ apollo (--version)
@apollo-annotation/cli/0.1.19 linux-x64 node-v18.20.3
@apollo-annotation/cli/0.1.19 darwin-x64 node-v20.10.0
$ apollo --help [COMMAND]
USAGE
$ apollo COMMAND
Expand All @@ -41,6 +41,8 @@ USAGE
- [`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) - Get Jbrowse
configuration from Apollo
- [`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
Expand Down
29 changes: 29 additions & 0 deletions packages/apollo-cli/src/commands/jbrowse/get-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { BaseCommand } from '../../baseCommand.js'
import { wrapLines, queryApollo } from '../../utils.js'

export default class GetConfig extends BaseCommand<typeof GetConfig> {
static summary = 'Get Jbrowse configuration from Apollo'
static description = wrapLines(
'Print to stdout the Jbrowse configuration from Apollo in json format',
)

public async run(): Promise<void> {
const { flags } = await this.parse(GetConfig)

const access: { address: string; accessToken: string } =
await this.getAccess(flags['config-file'], flags.profile)

const response = await queryApollo(
access.address,
access.accessToken,
'jbrowse/config.json',
)

if (!response.ok) {
throw new Error('Failed to fetch jbrowse configuration')
}

const json = (await response.json()) as object
this.log(JSON.stringify(json, null, 2))
}
}
75 changes: 75 additions & 0 deletions packages/apollo-cli/src/commands/jbrowse/set-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import * as fs from 'node:fs'
import {
ImportJBrowseConfigChange,
JBrowseConfig,
} from '@apollo-annotation/shared'
import { Flags } from '@oclif/core'
import { Agent, RequestInit, fetch } from 'undici'
import { ConfigError } from '../../ApolloConf.js'
import { BaseCommand } from '../../baseCommand.js'
import {
wrapLines,
localhostToAddress,
createFetchErrorMessage,
} from '../../utils.js'

export default class SetConfig extends BaseCommand<typeof SetConfig> {
static summary = 'Add jbrowse configuration'
static description = wrapLines(
'Add jbrowse configuration into apollo database',
)

static examples = [
{
description: 'Add jbrowse configuration:',
command: '<%= config.bin %> <%= command.id %> -i config.json',
},
]

static flags = {
'input-file': Flags.string({
char: 'i',
description: 'Input jbrowse configuration file',
required: true,
}),
}

async run(): Promise<void> {
const { flags } = await this.parse(SetConfig)

if (!fs.existsSync(flags['input-file'])) {
this.error(`File ${flags['input-file']} does not exist`)
}

const access: { address: string; accessToken: string } =
await this.getAccess(flags['config-file'], flags.profile)
const filehandle = await fs.promises.open(flags['input-file'])
const fileContent = await filehandle.readFile({ encoding: 'utf8' })
await filehandle.close()

const change = new ImportJBrowseConfigChange({
typeName: 'ImportJBrowseConfigChange',
newJBrowseConfig: JSON.parse(fileContent) as JBrowseConfig,
})

const auth: RequestInit = {
method: 'POST',
body: JSON.stringify(change),
headers: {
Authorization: `Bearer ${access.accessToken}`,
'Content-Type': 'application/json',
},
dispatcher: new Agent({ headersTimeout: 60 * 60 * 1000 }),
}
const url = new URL(localhostToAddress(`${access.address}/changes`))
const response = await fetch(url, auth)
if (!response.ok) {
const errorMessage = await createFetchErrorMessage(
response,
'Failed to add jbrowse configuration',
)
throw new ConfigError(errorMessage)
}
this.log('Jbrowse configuartion added successfully to apollo')
}
}
54 changes: 54 additions & 0 deletions packages/website/docs/cli/jbrowse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# `apollo jbrowse`

Get Jbrowse configuration from Apollo

- [`apollo jbrowse get-config`](#apollo-jbrowse-get-config)
- [`apollo jbrowse set-config`](#apollo-jbrowse-set-config)

## `apollo jbrowse get-config`

Get Jbrowse configuration from Apollo

```
USAGE
$ apollo jbrowse get-config [--profile <value>] [--config-file <value>]
FLAGS
--config-file=<value> Use this config file (mostly for testing)
--profile=<value> Use credentials from this profile
DESCRIPTION
Get Jbrowse configuration from Apollo
Print to stdout the Jbrowse configuration from Apollo in json format
```

_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`

Add jbrowse configuration

```
USAGE
$ apollo jbrowse set-config -i <value> [--profile <value>] [--config-file <value>]
FLAGS
-i, --input-file=<value> (required) Input jbrowse configuration file
--config-file=<value> Use this config file (mostly for testing)
--profile=<value> Use credentials from this profile
DESCRIPTION
Add jbrowse configuration
Add jbrowse configuration into apollo database
EXAMPLES
Add jbrowse configuration:
$ apollo jbrowse set-config -i 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)_

0 comments on commit 3da532b

Please sign in to comment.