@Test(description = "Test new command without arguments") public void testNewCommandNoArgs() throws IOException { String[] args = {}; NewCommand newCommand = new NewCommand(tmpDir, printStream); new CommandLine(newCommand).parse(args); newCommand.execute(); Assert.assertTrue(readOutput().contains("The following required arguments were not provided")); }
@Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(NEW_COMMAND); errStream.println(commandUsageInfo); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <project-name>", "ballerina new <project-name>", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina new <project-name>", true); return; } Path path = userDir.resolve(argList.get(0)); if (Files.exists(path)) { CommandUtil.printError(errStream, "destination '" + path.toString() + "' already exists", "ballerina new <project-name>", true); return; } Path projectRoot = ProjectDirs.findProjectRoot(path); if (projectRoot != null) { CommandUtil.printError(errStream, "Directory is already within a Ballerina project :" + projectRoot.toString(), null, false); return; } try { Files.createDirectories(path); CommandUtil.initProject(path); } catch (AccessDeniedException e) { errStream.println("error: Error occurred while creating project : " + "Insufficient Permission"); } catch (IOException e) { errStream.println("error: Error occurred while creating project : " + e.getMessage()); return; } errStream.println("Created new Ballerina project at " + userDir.relativize(path)); errStream.println(); errStream.println("Next:"); errStream.println(" Move into the project directory and use `ballerina add <module-name>` to"); errStream.println(" add a new Ballerina module."); }
NewCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(NEW_COMMAND); errStream.println(commandUsageInfo); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <project-name>", "ballerina new <project-name>", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina new <project-name>", true); return; } Path path = userDir.resolve(argList.get(0)); if (Files.exists(path)) { CommandUtil.printError(errStream, "destination '" + path.toString() + "' already exists", "ballerina new <project-name>", true); return; } Path projectRoot = ProjectDirs.findProjectRoot(path); if (projectRoot != null) { CommandUtil.printError(errStream, "Directory is already within a Ballerina project :" + projectRoot.toString(), null, false); return; } try { Files.createDirectories(path); CommandUtil.initProject(path); } catch (AccessDeniedException e) { errStream.println("error: Error occurred while creating project : " + "Insufficient Permission"); } catch (IOException e) { errStream.println("error: Error occurred while creating project : " + e.getMessage()); return; } errStream.println("Created new Ballerina project at " + userDir.relativize(path)); errStream.println(); errStream.println("Next:"); errStream.println(" Move into the project directory and use `ballerina add <module-name>` to"); errStream.println(" add a new Ballerina module."); } }
NewCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(NEW_COMMAND); errStream.println(commandUsageInfo); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <project-name>", "ballerina new <project-name>", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina new <project-name>", true); return; } Path path = userDir.resolve(argList.get(0)); if (Files.exists(path)) { CommandUtil.printError(errStream, "destination '" + path.toString() + "' already exists", "ballerina new <project-name>", true); return; } Path projectRoot = ProjectDirs.findProjectRoot(path); if (projectRoot != null) { CommandUtil.printError(errStream, "Directory is already within a Ballerina project :" + projectRoot.toString(), null, false); return; } try { Files.createDirectories(path); CommandUtil.initProject(path); } catch (AccessDeniedException e) { errStream.println("error: Error occurred while creating project : " + "Insufficient Permission"); } catch (IOException e) { errStream.println("error: Error occurred while creating project : " + e.getMessage()); return; } errStream.println("Created new Ballerina project at " + userDir.relativize(path)); errStream.println(); errStream.println("Next:"); errStream.println(" Move into the project directory and use `ballerina add <module-name>` to"); errStream.println(" add a new Ballerina module."); } NewCommand();  NewCommand(Path userDir, PrintStream errStream); }
NewCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(NEW_COMMAND); errStream.println(commandUsageInfo); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <project-name>", "ballerina new <project-name>", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina new <project-name>", true); return; } Path path = userDir.resolve(argList.get(0)); if (Files.exists(path)) { CommandUtil.printError(errStream, "destination '" + path.toString() + "' already exists", "ballerina new <project-name>", true); return; } Path projectRoot = ProjectDirs.findProjectRoot(path); if (projectRoot != null) { CommandUtil.printError(errStream, "Directory is already within a Ballerina project :" + projectRoot.toString(), null, false); return; } try { Files.createDirectories(path); CommandUtil.initProject(path); } catch (AccessDeniedException e) { errStream.println("error: Error occurred while creating project : " + "Insufficient Permission"); } catch (IOException e) { errStream.println("error: Error occurred while creating project : " + e.getMessage()); return; } errStream.println("Created new Ballerina project at " + userDir.relativize(path)); errStream.println(); errStream.println("Next:"); errStream.println(" Move into the project directory and use `ballerina add <module-name>` to"); errStream.println(" add a new Ballerina module."); } NewCommand();  NewCommand(Path userDir, PrintStream errStream); @Override void execute(); @Override String getName(); @Override void printLongDesc(StringBuilder out); @Override void printUsage(StringBuilder out); @Override void setParentCmdParser(CommandLine parentCmdParser); }
NewCommand implements BLauncherCmd { @Override public void execute() { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(NEW_COMMAND); errStream.println(commandUsageInfo); return; } if (null == argList) { CommandUtil.printError(errStream, "The following required arguments were not provided:\n" + " <project-name>", "ballerina new <project-name>", true); return; } if (!(1 == argList.size())) { CommandUtil.printError(errStream, "too many arguments.", "ballerina new <project-name>", true); return; } Path path = userDir.resolve(argList.get(0)); if (Files.exists(path)) { CommandUtil.printError(errStream, "destination '" + path.toString() + "' already exists", "ballerina new <project-name>", true); return; } Path projectRoot = ProjectDirs.findProjectRoot(path); if (projectRoot != null) { CommandUtil.printError(errStream, "Directory is already within a Ballerina project :" + projectRoot.toString(), null, false); return; } try { Files.createDirectories(path); CommandUtil.initProject(path); } catch (AccessDeniedException e) { errStream.println("error: Error occurred while creating project : " + "Insufficient Permission"); } catch (IOException e) { errStream.println("error: Error occurred while creating project : " + e.getMessage()); return; } errStream.println("Created new Ballerina project at " + userDir.relativize(path)); errStream.println(); errStream.println("Next:"); errStream.println(" Move into the project directory and use `ballerina add <module-name>` to"); errStream.println(" add a new Ballerina module."); } NewCommand();  NewCommand(Path userDir, PrintStream errStream); @Override void execute(); @Override String getName(); @Override void printLongDesc(StringBuilder out); @Override void printUsage(StringBuilder out); @Override void setParentCmdParser(CommandLine parentCmdParser);  }