Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI command to get and put JBrowse config files in collaboration server #437

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 linux-x64 node-v20.17.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) - 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
Expand Down
3 changes: 3 additions & 0 deletions packages/apollo-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"feature": {
"description": "Commands to handle features"
},
"jbrowse": {
"description": "Commands to manage the JBrowse configuration"
},
"refseq": {
"description": "Commands to handle reference sequences"
},
Expand Down
36 changes: 36 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,36 @@
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(

Check warning on line 6 in packages/apollo-cli/src/commands/jbrowse/get-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/get-config.ts#L5-L6

Added lines #L5 - L6 were not covered by tests
'Print to stdout the JBrowse configuration from Apollo in JSON format',
)

static examples = [

Check warning on line 10 in packages/apollo-cli/src/commands/jbrowse/get-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/get-config.ts#L10

Added line #L10 was not covered by tests
{
description: 'Get JBrowse configuration:',
command: '<%= config.bin %> <%= command.id %> > config.json',
},
]

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

Check warning on line 18 in packages/apollo-cli/src/commands/jbrowse/get-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/get-config.ts#L18

Added line #L18 was not covered by tests

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

Check warning on line 21 in packages/apollo-cli/src/commands/jbrowse/get-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/get-config.ts#L21

Added line #L21 was not covered by tests

const response = await queryApollo(

Check warning on line 23 in packages/apollo-cli/src/commands/jbrowse/get-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/get-config.ts#L23

Added line #L23 was not covered by tests
access.address,
access.accessToken,
'jbrowse/config.json',
)

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

Check warning on line 30 in packages/apollo-cli/src/commands/jbrowse/get-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/get-config.ts#L30

Added line #L30 was not covered by tests
}

const json = (await response.json()) as object
this.log(JSON.stringify(json, null, 2))

Check warning on line 34 in packages/apollo-cli/src/commands/jbrowse/get-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/get-config.ts#L33-L34

Added lines #L33 - L34 were not covered by tests
}
}
73 changes: 73 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,73 @@
import * as fs from 'node:fs'
import {
type JBrowseConfig,
type SerializedImportJBrowseConfigChange,
} from '@apollo-annotation/shared'
import { Args } 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 = 'Set JBrowse configuration'
static description = wrapLines(

Check warning on line 18 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L17-L18

Added lines #L17 - L18 were not covered by tests
'Set JBrowse configuration in Apollo collaboration server',
)

static examples = [

Check warning on line 22 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L22

Added line #L22 was not covered by tests
{
description: 'Add JBrowse configuration:',
command: '<%= config.bin %> <%= command.id %> config.json',
},
]

static args = {

Check warning on line 29 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L29

Added line #L29 was not covered by tests
inputFile: Args.string({
description: 'JBrowse configuration file',
required: true,
}),
}

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

Check warning on line 37 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L37

Added line #L37 was not covered by tests

if (!fs.existsSync(args.inputFile)) {
this.error(`File ${args.inputFile} does not exist`)

Check warning on line 40 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L40

Added line #L40 was not covered by tests
}

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

Check warning on line 47 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L44-L47

Added lines #L44 - L47 were not covered by tests

const change: SerializedImportJBrowseConfigChange = {

Check warning on line 49 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L49

Added line #L49 was not covered by tests
typeName: 'ImportJBrowseConfigChange',
newJBrowseConfig: JSON.parse(fileContent) as JBrowseConfig,
}

const auth: RequestInit = {

Check warning on line 54 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L54

Added line #L54 was not covered by tests
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)

Check warning on line 64 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L63-L64

Added lines #L63 - L64 were not covered by tests
if (!response.ok) {
const errorMessage = await createFetchErrorMessage(

Check warning on line 66 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L66

Added line #L66 was not covered by tests
response,
'Failed to add JBrowse configuration',
)
throw new ConfigError(errorMessage)

Check warning on line 70 in packages/apollo-cli/src/commands/jbrowse/set-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/jbrowse/set-config.ts#L70

Added line #L70 was not covered by tests
}
}
}
61 changes: 61 additions & 0 deletions packages/website/docs/cli/jbrowse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# `apollo jbrowse`

Commands to manage the JBrowse configuration

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

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

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 <value>] [--config-file <value>]

ARGUMENTS
INPUTFILE JBrowse configuration file

FLAGS
--config-file=<value> Use this config file (mostly for testing)
--profile=<value> 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)_