From 7ff6201e6b0f2125db281452620fbd775e31d34a Mon Sep 17 00:00:00 2001 From: Mohamed Ishad Date: Sat, 19 Oct 2024 21:18:21 +0530 Subject: [PATCH] Validate command arguments --- src/main/java/org/ballerinalang/command/Main.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/ballerinalang/command/Main.java b/src/main/java/org/ballerinalang/command/Main.java index 1b039fe8..fbc9e9e4 100644 --- a/src/main/java/org/ballerinalang/command/Main.java +++ b/src/main/java/org/ballerinalang/command/Main.java @@ -115,9 +115,14 @@ private static Optional getInvokedCmd(String... args) { cmdParser.setCommandName("ballerina"); cmdParser.setPosixClusteredShortOptionsAllowed(false); + CommandLine.ParseResult parseResult = cmdParser.parseArgs(args); List parsedCommands = cmdParser.parse(args); + if (parseResult.hasSubcommand()) { + return Optional.of((BCommand) parseResult.subcommand().commandSpec().userObject()); + } + if (parsedCommands.size() < 1) { return Optional.of(defaultCmd); }