diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java index 232919f7640..2a437684839 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java @@ -40,7 +40,7 @@ public static void main(String[] args) { return; } String command = resolveCommand(line); - String entity = resolveEntity(line, command != null); + String entity = resolveEntity(line); GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); commandLine.handleCommandLine(); } catch (ParseException exp) { @@ -76,13 +76,12 @@ protected static String resolveCommand(CommandLine line) { * Determines the entity to act upon based on the command line input. * * @param line Parsed command line object. - * @param command true if command is an argument * @return The entity, e.g. metakalake, catalog, schema, table, etc. */ protected static String resolveEntity(CommandLine line) { /* As the bare first argument. */ String[] args = line.getArgs(); - + if (args.length > 0) { String entity = args[0]; if (CommandEntities.isValidEntity(entity)) { diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java index d873d2a2d58..c1bf5262b89 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java @@ -66,48 +66,7 @@ public void entityNotFound() throws Exception { } @Test -<<<<<<< HEAD - public void justName() throws Exception, MissingArgumentException { - String[] args = {"--name"}; - - assertThrows(MissingArgumentException.class, () -> new DefaultParser().parse(options, args)); - } - - @Test - public void catalogFromCommandLineOption() throws Exception { - String[] args = {"--catalog", "catalogA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String catalogName = fullName.getCatalogName(); - assertEquals("catalogA", catalogName); - } - - @Test - public void schemaFromCommandLineOption() throws Exception { - String[] args = {"--schema", "schemaA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String schemaName = fullName.getSchemaName(); - assertEquals("schemaA", schemaName); - } - - @Test - public void tableFromCommandLineOption() throws Exception { - String[] args = {"--table", "tableA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String tableName = fullName.getTableName(); - assertEquals("tableA", tableName); - } - - @Test - public void malformedMissingEntityName() throws Exception { -======= public void malformedName() throws Exception { ->>>>>>> CLI String[] args = {"--name", "metalake.catalog"}; CommandLine commandLine = new DefaultParser().parse(options, args); FullName fullName = new FullName(commandLine); diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java index 8c30b9ac6e6..3187c611706 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java @@ -62,7 +62,7 @@ public void withTwoArgsOnly() throws ParseException { String command = Main.resolveCommand(line); assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); + String entity = Main.resolveEntity(line); assertEquals(CommandEntities.METALAKE, entity); } @@ -70,12 +70,12 @@ public void withTwoArgsOnly() throws ParseException { public void defaultToDetails() throws ParseException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); - String[] args = {"--metalake", "metalake_demo"}; + String[] args = {"metalake", "--name", "metalake_demo"}; CommandLine line = parser.parse(options, args); String command = Main.resolveCommand(line); assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, false); + String entity = Main.resolveEntity(line); assertEquals(CommandEntities.METALAKE, entity); } @@ -104,59 +104,16 @@ public void parseError() throws UnsupportedEncodingException { assertTrue(outContent.toString().contains("usage:")); // Expect help output } - @Test - public void catalogWithTwoArgs() throws ParseException { - Options options = new GravitinoOptions().options(); - CommandLineParser parser = new DefaultParser(); - String[] args = {"catalog", "details", "--name", "metalake_demo.catalog_postgres"}; - CommandLine line = parser.parse(options, args); - - String command = Main.resolveCommand(line); - assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); - assertEquals(CommandEntities.CATALOG, entity); - } - @Test public void catalogWithOneArg() throws ParseException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); - String[] args = {"catalog", "--command", "details", "--name", "metalake_demo.catalog_postgres"}; - CommandLine line = parser.parse(options, args); - - String command = Main.resolveCommand(line); - assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); - assertEquals(CommandEntities.CATALOG, entity); - } - - @Test - public void catalogWithEntity() throws ParseException { - Options options = new GravitinoOptions().options(); - CommandLineParser parser = new DefaultParser(); - String[] args = { - "--entity", "catalog", "--command", "details", "--name", "metalake_demo.catalog_postgres" - }; - CommandLine line = parser.parse(options, args); - - String command = Main.resolveCommand(line); - assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, false); - assertEquals(CommandEntities.CATALOG, entity); - } - - @Test - public void catalogWithNoName() throws ParseException { - Options options = new GravitinoOptions().options(); - CommandLineParser parser = new DefaultParser(); - String[] args = { - "catalog", "details", "--metalake", "metalake_demo", "--catalog", "catalog_postgres" - }; + String[] args = {"catalog", "--details", "--name", "metalake_demo.catalog_postgres"}; CommandLine line = parser.parse(options, args); String command = Main.resolveCommand(line); assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); + String entity = Main.resolveEntity(line); assertEquals(CommandEntities.CATALOG, entity); } }