Skip to content

Commit

Permalink
feat: use core flags in remaining command
Browse files Browse the repository at this point in the history
  • Loading branch information
Amzani committed Jun 4, 2024
1 parent beecfb8 commit bbb8ee1
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { promises } from 'fs';
import path from 'path';
import { Specification } from '../core/models/SpecificationFile';
import { Document } from '@asyncapi/bundler/lib/document';
import { bundleFlags } from 'core/flags/bundle.flags';
import { bundleFlags } from '../core/flags/bundle.flags';

const { writeFile } = promises;

Expand Down
1 change: 0 additions & 1 deletion src/commands/config/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default class Analytics extends Command {
disable: Flags.boolean({ char: 'd', description: 'disable analytics', default: false }),
enable: Flags.boolean({ char: 'e', description: 'enable analytics', default: false }),
status: Flags.boolean({ char: 's', description: 'show current status of analytics' }),

};

async run() {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/context/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MissingContextFileError,
ContextFileWrongFormatError,
} from '../../../core/errors/context-error';
import { addFlags } from 'core/flags/config/context.flags';
import { addFlags } from '../../../core/flags/config/context.flags';

export default class ContextAdd extends Command {
static description = 'Add a context to the store';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/context/current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ContextFileEmptyError,
ContextNotFoundError,
} from '../../../core/errors/context-error';
import { helpFlag } from 'core/flags/global.flags';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextCurrent extends Command {
static description = 'Shows the current context that is being used';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/context/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ContextFileWrongFormatError,
ContextFileEmptyError,
} from '../../../core/errors/context-error';
import { helpFlag } from 'core/flags/global.flags';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextEdit extends Command {
static description = 'Edit a context in the store';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/context/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Args } from '@oclif/core';
import Command from '../../../core/base';
import { initContext } from '../../../core/models/Context';
import { helpFlag } from 'core/flags/global.flags';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextInit extends Command {
static description = 'Initialize context';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/context/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MissingContextFileError,
ContextFileWrongFormatError,
} from '../../../core/errors/context-error';
import { helpFlag } from 'core/flags/global.flags';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextList extends Command {
static description = 'List all the stored contexts in the store';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/context/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ContextFileWrongFormatError,
ContextFileEmptyError,
} from '../../../core/errors/context-error';
import { helpFlag } from 'core/flags/global.flags';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextRemove extends Command {
static description = 'Delete a context from the store';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/context/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ContextFileWrongFormatError,
ContextFileEmptyError,
} from '../../../core/errors/context-error';
import { helpFlag } from 'core/flags/global.flags';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextUse extends Command {
static description = 'Set a context as current';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Command from '../../core/base';
import {loadHelpClass} from '@oclif/core';
import { loadHelpClass } from '@oclif/core';

export default class Config extends Command {
static description = 'CLI config settings';
Expand Down
6 changes: 2 additions & 4 deletions src/commands/config/versions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Flags } from '@oclif/core';
import Command from '../../core/base';
import { helpFlag } from '../../core/flags/global.flags';

export default class Versions extends Command {
static description = 'Show versions of AsyncAPI tools used';

static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

async run() {
const dependencies: string[] = [];
Expand Down
9 changes: 3 additions & 6 deletions src/commands/convert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { promises as fPromises } from 'fs';
import { Flags, Args } from '@oclif/core';
import { Args } from '@oclif/core';
import Command from '../core/base';
import { ValidationError } from '../core/errors/validation-error';
import { load } from '../core/models/SpecificationFile';
Expand All @@ -11,17 +11,14 @@ import { cyan, green } from 'picocolors';

// @ts-ignore
import specs from '@asyncapi/specs';
import { convertFlags } from '../core/flags/convert.flags';

const latestVersion = Object.keys(specs.schemas).pop() as string;

export default class Convert extends Command {
static description = 'Convert asyncapi documents older to newer versions';

static flags = {
help: Flags.help({ char: 'h' }),
output: Flags.string({ char: 'o', description: 'path to the file where the result is saved' }),
'target-version': Flags.string({ char: 't', description: 'asyncapi version to convert to', default: latestVersion })
};
static flags = convertFlags(latestVersion);

static args = {
'spec-file': Args.string({description: 'spec path, url, or context-name', required: false}),
Expand Down
36 changes: 4 additions & 32 deletions src/commands/diff.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Flags, Args } from '@oclif/core';
import { Args } from '@oclif/core';
import * as diff from '@asyncapi/diff';
import AsyncAPIDiff from '@asyncapi/diff/lib/asyncapidiff';
import { promises as fs } from 'fs';
Expand All @@ -14,45 +14,17 @@ import {
DiffOverrideJSONError,
} from '../core/errors/diff-error';
import { specWatcher } from '../core/globals';
import { watchFlag } from '../core/flagsD/global.flags';
import { validationFlags, parse, convertToOldAPI } from '../core/parser';
import { parse, convertToOldAPI } from '../core/parser';

import type { SpecWatcherParams } from '../core/globals';
import { diffFlags } from '../core/flags/diff.flags';

const { readFile } = fs;

export default class Diff extends Command {
static description = 'Find diff between two asyncapi files';

static flags = {
help: Flags.help({ char: 'h' }),
format: Flags.string({
char: 'f',
description: 'format of the output',
default: 'yaml',
options: ['json', 'yaml', 'yml', 'md'],
}),
type: Flags.string({
char: 't',
description: 'type of the output',
default: 'all',
options: ['breaking', 'non-breaking', 'unclassified', 'all'],
}),
markdownSubtype: Flags.string({
description: 'the format of changes made to AsyncAPI document. It works only when diff is generated using md type. For example, when you specify subtype as json, then diff information in markdown is dumped as json structure.',
default: undefined,
options: ['json', 'yaml', 'yml']
}),
overrides: Flags.string({
char: 'o',
description: 'path to JSON file containing the override properties',
}),
'no-error': Flags.boolean({
description: 'don\'t show error on breaking changes',
}),
watch: watchFlag(),
...validationFlags({ logDiagnostics: false }),
};
static flags = diffFlags();

static args = {
old: Args.string({description: 'old spec path, URL or context-name', required: true}),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/fromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Parser } from '@asyncapi/parser';
import { intro, isCancel, spinner, text } from '@clack/prompts';
import { inverse, yellow, magenta, green, red } from 'picocolors';
import fetch from 'node-fetch';
import { fromTemplateFlags } from 'core/flags/generate/fromTemplate.flags';
import { fromTemplateFlags } from '../../core/flags/generate/fromTemplate.flags';

interface IMapBaseUrlToFlag {
url: string,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { cancel, intro, isCancel, select, spinner, text } from '@clack/prompts';
import { green, inverse } from 'picocolors';

import type { AbstractFileGenerator, AbstractGenerator } from '@asyncapi/modelina';
import { modelsFlags } from 'core/flags/generate/models.flags';
import { modelsFlags } from '../../core/flags/generate/models.flags';

enum Languages {
typescript = 'typescript',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/new/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { start as startStudio, DEFAULT_PORT } from '../../core/models/Studio';
import { resolve } from 'path';
import { load } from '../../core/models/SpecificationFile';
import { cyan } from 'picocolors';
import { fileFlags } from 'core/flags/new/file.flags';
import { fileFlags } from '../../core/flags/new/file.flags';

const { writeFile, readFile } = fPromises;
const DEFAULT_ASYNCAPI_FILE_NAME = 'asyncapi.yaml';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/new/glee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { prompt } from 'inquirer';
// @ts-ignore
import Generator from '@asyncapi/generator';
import { cyan, gray } from 'picocolors';
import { gleeFlags } from 'core/flags/new/glee.flags';
import { gleeFlags } from '../../core/flags/new/glee.flags';

export const successMessage = (projectName: string) =>
`🎉 Your Glee project has been successfully created!
Expand Down
10 changes: 3 additions & 7 deletions src/commands/optimize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flags, Args } from '@oclif/core';
import { Args } from '@oclif/core';
import { Optimizer, Output, Report, ReportElement } from '@asyncapi/optimizer';
import Command from '../core/base';
import { ValidationError } from '../core/errors/validation-error';
Expand All @@ -7,6 +7,7 @@ import * as inquirer from 'inquirer';
import chalk from 'chalk';
import { promises } from 'fs';
import { Parser } from '@asyncapi/parser';
import { optimizeFlags } from '../core/flags/optimize.flags';

const { writeFile } = promises;

Expand Down Expand Up @@ -35,12 +36,7 @@ export default class Optimize extends Command {
'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty',
];

static flags = {
help: Flags.help({ char: 'h' }),
optimization: Flags.string({char: 'p', default: Object.values(Optimizations), options: Object.values(Optimizations), multiple: true, description: 'select the type of optimizations that you want to apply.'}),
output: Flags.string({char: 'o', default: Outputs.TERMINAL, options: Object.values(Outputs), description: 'select where you want the output.'}),
'no-tty': Flags.boolean({ description: 'do not use an interactive terminal', default: false }),
};
static flags = optimizeFlags();

static args = {
'spec-file': Args.string({description: 'spec path, url, or context-name', required: false}),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/start/studio.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Command from '../../core/base';
import { start as startStudio } from '../../core/models/Studio';
import { load } from '../../core/models/SpecificationFile';
import { studioFlags } from 'core/flags/start/studio.flags';
import { studioFlags } from '../../core/flags/start/studio.flags';

export default class StartStudio extends Command {
static description = 'starts a new local instance of Studio';
Expand Down
12 changes: 4 additions & 8 deletions src/commands/validate.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { Flags, Args } from '@oclif/core';
import { Args } from '@oclif/core';
import Command from '../core/base';
import { validate, validationFlags, ValidateOptions, ValidationStatus } from '../core/parser';
import { validate, ValidateOptions, ValidationStatus } from '../core/parser';
import { load } from '../core/models/SpecificationFile';
import { specWatcher } from '../core/globals';
import { watchFlag } from '../core/flagsD/global.flags';
import { validateFlags } from '../core/flags/validate.flags';

export default class Validate extends Command {
static description = 'validate asyncapi file';

static flags = {
help: Flags.help({ char: 'h' }),
watch: watchFlag(),
...validationFlags(),
};
static flags = validateFlags();

static args = {
'spec-file': Args.string({description: 'spec path, url, or context-name', required: false}),
Expand Down

0 comments on commit bbb8ee1

Please sign in to comment.