From bbb8ee1dc944bc0484bbdd680dc3a9af57224f29 Mon Sep 17 00:00:00 2001 From: Samir AMZANI Date: Tue, 4 Jun 2024 11:24:28 +0200 Subject: [PATCH] feat: use core flags in remaining command --- src/commands/bundle.ts | 2 +- src/commands/config/analytics.ts | 1 - src/commands/config/context/add.ts | 2 +- src/commands/config/context/current.ts | 2 +- src/commands/config/context/edit.ts | 2 +- src/commands/config/context/init.ts | 2 +- src/commands/config/context/list.ts | 2 +- src/commands/config/context/remove.ts | 2 +- src/commands/config/context/use.ts | 2 +- src/commands/config/index.ts | 2 +- src/commands/config/versions.ts | 6 ++--- src/commands/convert.ts | 9 +++---- src/commands/diff.ts | 36 +++----------------------- src/commands/generate/fromTemplate.ts | 2 +- src/commands/generate/models.ts | 2 +- src/commands/new/file.ts | 2 +- src/commands/new/glee.ts | 2 +- src/commands/optimize.ts | 10 +++---- src/commands/start/studio.ts | 2 +- src/commands/validate.ts | 12 +++------ 20 files changed, 30 insertions(+), 72 deletions(-) diff --git a/src/commands/bundle.ts b/src/commands/bundle.ts index 58aaa4fe2c8..b1867cd80f8 100644 --- a/src/commands/bundle.ts +++ b/src/commands/bundle.ts @@ -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; diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index b8a1dc4eacf..3c8e056d01b 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -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() { diff --git a/src/commands/config/context/add.ts b/src/commands/config/context/add.ts index b6e575b2b8e..f17e19480fd 100644 --- a/src/commands/config/context/add.ts +++ b/src/commands/config/context/add.ts @@ -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'; diff --git a/src/commands/config/context/current.ts b/src/commands/config/context/current.ts index 78fdacba427..49067e33dae 100644 --- a/src/commands/config/context/current.ts +++ b/src/commands/config/context/current.ts @@ -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'; diff --git a/src/commands/config/context/edit.ts b/src/commands/config/context/edit.ts index 94253c9f241..f16409e9141 100644 --- a/src/commands/config/context/edit.ts +++ b/src/commands/config/context/edit.ts @@ -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'; diff --git a/src/commands/config/context/init.ts b/src/commands/config/context/init.ts index 41e054a38f2..40d4dc7ab2c 100644 --- a/src/commands/config/context/init.ts +++ b/src/commands/config/context/init.ts @@ -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'; diff --git a/src/commands/config/context/list.ts b/src/commands/config/context/list.ts index d5611991d70..2286173c00c 100644 --- a/src/commands/config/context/list.ts +++ b/src/commands/config/context/list.ts @@ -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'; diff --git a/src/commands/config/context/remove.ts b/src/commands/config/context/remove.ts index d8355573fd9..9a29cd6770d 100644 --- a/src/commands/config/context/remove.ts +++ b/src/commands/config/context/remove.ts @@ -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'; diff --git a/src/commands/config/context/use.ts b/src/commands/config/context/use.ts index 5eb8f8f5904..6450d524047 100644 --- a/src/commands/config/context/use.ts +++ b/src/commands/config/context/use.ts @@ -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'; diff --git a/src/commands/config/index.ts b/src/commands/config/index.ts index ac5694a022f..ecf71751036 100644 --- a/src/commands/config/index.ts +++ b/src/commands/config/index.ts @@ -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'; diff --git a/src/commands/config/versions.ts b/src/commands/config/versions.ts index aa48e739113..915f83ccb3f 100644 --- a/src/commands/config/versions.ts +++ b/src/commands/config/versions.ts @@ -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[] = []; diff --git a/src/commands/convert.ts b/src/commands/convert.ts index b12d20c5923..eb51bf90eae 100644 --- a/src/commands/convert.ts +++ b/src/commands/convert.ts @@ -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'; @@ -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}), diff --git a/src/commands/diff.ts b/src/commands/diff.ts index 2f0779e65dd..5c75211baa4 100644 --- a/src/commands/diff.ts +++ b/src/commands/diff.ts @@ -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'; @@ -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}), diff --git a/src/commands/generate/fromTemplate.ts b/src/commands/generate/fromTemplate.ts index 9ded9dc9025..58b0d782391 100644 --- a/src/commands/generate/fromTemplate.ts +++ b/src/commands/generate/fromTemplate.ts @@ -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, diff --git a/src/commands/generate/models.ts b/src/commands/generate/models.ts index 9aad182be98..5a8d853efeb 100644 --- a/src/commands/generate/models.ts +++ b/src/commands/generate/models.ts @@ -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', diff --git a/src/commands/new/file.ts b/src/commands/new/file.ts index 4382016ff5a..ea5c5560a5f 100644 --- a/src/commands/new/file.ts +++ b/src/commands/new/file.ts @@ -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'; diff --git a/src/commands/new/glee.ts b/src/commands/new/glee.ts index 3645ec0d458..8b4aa698e5d 100644 --- a/src/commands/new/glee.ts +++ b/src/commands/new/glee.ts @@ -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! diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index 275fcd1be9c..d5e81f4e499 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -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'; @@ -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; @@ -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}), diff --git a/src/commands/start/studio.ts b/src/commands/start/studio.ts index 8dae6dbacc7..5e197b63057 100644 --- a/src/commands/start/studio.ts +++ b/src/commands/start/studio.ts @@ -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'; diff --git a/src/commands/validate.ts b/src/commands/validate.ts index e9626b100c5..fb3b32d6df4 100644 --- a/src/commands/validate.ts +++ b/src/commands/validate.ts @@ -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}),