Skip to content

Commit

Permalink
Handle the invalid command resulting in infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
samirsilwal committed Oct 26, 2024
1 parent 8322436 commit c9a1cfb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
// This script checks if the command-line argument provided is one of the available commands.
// If the command is not recognized, it prints an error message and exits the process.
import { printError } from '../util/io';

(async () => {
const availableCommands = [

Check warning on line 6 in src/commands/index.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/index.ts#L5-L6

Added lines #L5 - L6 were not covered by tests
'--help',
'make-publish',
'make',
'migrate-latest',
'migrate-list',
'migrate-rollback',
'prune',
'synchronize',
'--version'
];

// Check if there are at least 3 arguments (node, script, command)
// and if the command is not in the list of available commands
if (process.argv.length >= 3 && !availableCommands.includes(process.argv[2])) {
await printError(`Invalid command. Please use one of the following commands: ${availableCommands.join(', ')}`);

Check warning on line 21 in src/commands/index.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/index.ts#L21

Added line #L21 was not covered by tests
// Exit the process with a status code of 1 (indicating an error)
process.exit(1);

Check warning on line 23 in src/commands/index.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/index.ts#L23

Added line #L23 was not covered by tests
}
})();

export { run } from '@oclif/command';

0 comments on commit c9a1cfb

Please sign in to comment.