Skip to content

Commit

Permalink
feat: support context file location in repository
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Jul 4, 2023
1 parent 6e3b2ae commit e160a2f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/commands/config/context/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Command from '../../../base';
import { addContext } from '../../../models/Context';

export default class ContextAdd extends Command {
static description='Add or modify a context in the store';
static description='Add a context to the store';
static flags = {
help: Flags.help({char: 'h'})
};
Expand Down
24 changes: 24 additions & 0 deletions src/commands/config/context/edit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Flags} from '@oclif/core';
import Command from '../../../base';
import { editContext } from '../../../models/Context';

export default class ContextEdit extends Command {
static description='Edit a context in the store';
static flags = {
help: Flags.help({char: 'h'})
};

static args = [
{name: 'context-name', description: 'context name', required: true},
{name: 'spec-file-path', description: 'file path of the spec file', required: true}
];

async run() {
const {args} = await this.parse(ContextEdit);
const contextName = args['context-name'];
const specFilePath = args['spec-file-path'];

await editContext(contextName, specFilePath);
this.log(`Edited context "${contextName}".\n\nYou can set it as your current context: asyncapi config context use ${contextName}\nYou can use this context when needed by passing ${contextName} as a parameter: asyncapi validate ${contextName}`);
}
}
12 changes: 12 additions & 0 deletions src/models/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ export async function addContext(contextName: string, pathToFile: string) {
await saveContextFile(fileContent);
}

export async function editContext(contextName: string, pathToFile: string) {
let fileContent: IContextFile;

try {
fileContent = await loadContextFile();
} catch (e) {
throw e;
}
fileContent.store[String(contextName)] = pathToFile;
await saveContextFile(fileContent);
}

export async function removeContext(contextName: string) {
const fileContent: IContextFile = await loadContextFile();
if (!fileContent.store[String(contextName)]) {
Expand Down

0 comments on commit e160a2f

Please sign in to comment.