@Test(description = "Test add command without arguments") public void testAddCommandNoArgs() throws IOException { String[] args = {}; AddCommand addCommand = new AddCommand(projectPath, printStream); new CommandLine(addCommand).parseArgs(args); addCommand.execute(); Assert.assertTrue(readOutput().contains("The following required arguments were not provided")); }
@Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(ADD_COMMAND); errStream.println(commandUsageInfo); return; } if (list) { errStream.println("Available templates:"); for (String template : getTemplates()) { errStream.println(" - " + template); } for (String template : getBaloTemplates()) { errStream.println(" - " + template); } return; } Path projectPath = ProjectDirs.findProjectRoot(userDir); if (null == projectPath) { CommandUtil.printError(errStream, "not a ballerina project (or any parent up to mount point)\n" + "You should run this command inside a ballerina project", null, false); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <module-name>", "ballerina add <module-name> [-t|--template <template-name>]", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina add <project-name>", true); return; } String moduleName = argList.get(0); boolean matches = RepoUtils.validatePkg(moduleName); if (!matches) { CommandUtil.printError(errStream, "Invalid module name : '" + moduleName + "' :\n" + "Module name can only contain alphanumerics, underscores and periods " + "and the maximum length is 256 characters", null, false); return; } if (ProjectDirs.isModuleExist(projectPath, moduleName)) { CommandUtil.printError(errStream, "A module already exists with the given name : '" + moduleName + "' :\n" + "Existing module path " + projectPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(moduleName), null, false); return; } if (!getTemplates().contains(template) && findBaloTemplate(template) == null) { CommandUtil.printError(errStream, "Template not found, use `ballerina add --list` to view available templates.", null, false); return; } try { createModule(projectPath, moduleName, template); } catch (ModuleCreateException e) { CommandUtil.printError(errStream, "Error occurred while creating module : " + e.getMessage(), null, false); return; } errStream.println("Added new ballerina module at '" + userDir.relativize(projectPath .resolve(ProjectDirConstants.SOURCE_DIR_NAME) .resolve(moduleName)) + "'"); }
AddCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(ADD_COMMAND); errStream.println(commandUsageInfo); return; } if (list) { errStream.println("Available templates:"); for (String template : getTemplates()) { errStream.println(" - " + template); } for (String template : getBaloTemplates()) { errStream.println(" - " + template); } return; } Path projectPath = ProjectDirs.findProjectRoot(userDir); if (null == projectPath) { CommandUtil.printError(errStream, "not a ballerina project (or any parent up to mount point)\n" + "You should run this command inside a ballerina project", null, false); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <module-name>", "ballerina add <module-name> [-t|--template <template-name>]", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina add <project-name>", true); return; } String moduleName = argList.get(0); boolean matches = RepoUtils.validatePkg(moduleName); if (!matches) { CommandUtil.printError(errStream, "Invalid module name : '" + moduleName + "' :\n" + "Module name can only contain alphanumerics, underscores and periods " + "and the maximum length is 256 characters", null, false); return; } if (ProjectDirs.isModuleExist(projectPath, moduleName)) { CommandUtil.printError(errStream, "A module already exists with the given name : '" + moduleName + "' :\n" + "Existing module path " + projectPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(moduleName), null, false); return; } if (!getTemplates().contains(template) && findBaloTemplate(template) == null) { CommandUtil.printError(errStream, "Template not found, use `ballerina add --list` to view available templates.", null, false); return; } try { createModule(projectPath, moduleName, template); } catch (ModuleCreateException e) { CommandUtil.printError(errStream, "Error occurred while creating module : " + e.getMessage(), null, false); return; } errStream.println("Added new ballerina module at '" + userDir.relativize(projectPath .resolve(ProjectDirConstants.SOURCE_DIR_NAME) .resolve(moduleName)) + "'"); } }
AddCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(ADD_COMMAND); errStream.println(commandUsageInfo); return; } if (list) { errStream.println("Available templates:"); for (String template : getTemplates()) { errStream.println(" - " + template); } for (String template : getBaloTemplates()) { errStream.println(" - " + template); } return; } Path projectPath = ProjectDirs.findProjectRoot(userDir); if (null == projectPath) { CommandUtil.printError(errStream, "not a ballerina project (or any parent up to mount point)\n" + "You should run this command inside a ballerina project", null, false); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <module-name>", "ballerina add <module-name> [-t|--template <template-name>]", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina add <project-name>", true); return; } String moduleName = argList.get(0); boolean matches = RepoUtils.validatePkg(moduleName); if (!matches) { CommandUtil.printError(errStream, "Invalid module name : '" + moduleName + "' :\n" + "Module name can only contain alphanumerics, underscores and periods " + "and the maximum length is 256 characters", null, false); return; } if (ProjectDirs.isModuleExist(projectPath, moduleName)) { CommandUtil.printError(errStream, "A module already exists with the given name : '" + moduleName + "' :\n" + "Existing module path " + projectPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(moduleName), null, false); return; } if (!getTemplates().contains(template) && findBaloTemplate(template) == null) { CommandUtil.printError(errStream, "Template not found, use `ballerina add --list` to view available templates.", null, false); return; } try { createModule(projectPath, moduleName, template); } catch (ModuleCreateException e) { CommandUtil.printError(errStream, "Error occurred while creating module : " + e.getMessage(), null, false); return; } errStream.println("Added new ballerina module at '" + userDir.relativize(projectPath .resolve(ProjectDirConstants.SOURCE_DIR_NAME) .resolve(moduleName)) + "'"); } AddCommand();  AddCommand(Path userDir, PrintStream errStream);  AddCommand(Path userDir, PrintStream errStream, Path homeCache); }
AddCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(ADD_COMMAND); errStream.println(commandUsageInfo); return; } if (list) { errStream.println("Available templates:"); for (String template : getTemplates()) { errStream.println(" - " + template); } for (String template : getBaloTemplates()) { errStream.println(" - " + template); } return; } Path projectPath = ProjectDirs.findProjectRoot(userDir); if (null == projectPath) { CommandUtil.printError(errStream, "not a ballerina project (or any parent up to mount point)\n" + "You should run this command inside a ballerina project", null, false); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <module-name>", "ballerina add <module-name> [-t|--template <template-name>]", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina add <project-name>", true); return; } String moduleName = argList.get(0); boolean matches = RepoUtils.validatePkg(moduleName); if (!matches) { CommandUtil.printError(errStream, "Invalid module name : '" + moduleName + "' :\n" + "Module name can only contain alphanumerics, underscores and periods " + "and the maximum length is 256 characters", null, false); return; } if (ProjectDirs.isModuleExist(projectPath, moduleName)) { CommandUtil.printError(errStream, "A module already exists with the given name : '" + moduleName + "' :\n" + "Existing module path " + projectPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(moduleName), null, false); return; } if (!getTemplates().contains(template) && findBaloTemplate(template) == null) { CommandUtil.printError(errStream, "Template not found, use `ballerina add --list` to view available templates.", null, false); return; } try { createModule(projectPath, moduleName, template); } catch (ModuleCreateException e) { CommandUtil.printError(errStream, "Error occurred while creating module : " + e.getMessage(), null, false); return; } errStream.println("Added new ballerina module at '" + userDir.relativize(projectPath .resolve(ProjectDirConstants.SOURCE_DIR_NAME) .resolve(moduleName)) + "'"); } AddCommand();  AddCommand(Path userDir, PrintStream errStream);  AddCommand(Path userDir, PrintStream errStream, Path homeCache); @Override void execute(); @Override String getName(); @Override void printLongDesc(StringBuilder out); @Override void printUsage(StringBuilder out); @Override void setParentCmdParser(CommandLine parentCmdParser); }
AddCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(ADD_COMMAND); errStream.println(commandUsageInfo); return; } if (list) { errStream.println("Available templates:"); for (String template : getTemplates()) { errStream.println(" - " + template); } for (String template : getBaloTemplates()) { errStream.println(" - " + template); } return; } Path projectPath = ProjectDirs.findProjectRoot(userDir); if (null == projectPath) { CommandUtil.printError(errStream, "not a ballerina project (or any parent up to mount point)\n" + "You should run this command inside a ballerina project", null, false); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <module-name>", "ballerina add <module-name> [-t|--template <template-name>]", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina add <project-name>", true); return; } String moduleName = argList.get(0); boolean matches = RepoUtils.validatePkg(moduleName); if (!matches) { CommandUtil.printError(errStream, "Invalid module name : '" + moduleName + "' :\n" + "Module name can only contain alphanumerics, underscores and periods " + "and the maximum length is 256 characters", null, false); return; } if (ProjectDirs.isModuleExist(projectPath, moduleName)) { CommandUtil.printError(errStream, "A module already exists with the given name : '" + moduleName + "' :\n" + "Existing module path " + projectPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(moduleName), null, false); return; } if (!getTemplates().contains(template) && findBaloTemplate(template) == null) { CommandUtil.printError(errStream, "Template not found, use `ballerina add --list` to view available templates.", null, false); return; } try { createModule(projectPath, moduleName, template); } catch (ModuleCreateException e) { CommandUtil.printError(errStream, "Error occurred while creating module : " + e.getMessage(), null, false); return; } errStream.println("Added new ballerina module at '" + userDir.relativize(projectPath .resolve(ProjectDirConstants.SOURCE_DIR_NAME) .resolve(moduleName)) + "'"); } AddCommand();  AddCommand(Path userDir, PrintStream errStream);  AddCommand(Path userDir, PrintStream errStream, Path homeCache); @Override void execute(); @Override String getName(); @Override void printLongDesc(StringBuilder out); @Override void printUsage(StringBuilder out); @Override void setParentCmdParser(CommandLine parentCmdParser);  }