test_class.file: cli/ballerina-packerina/src/test/java/org/ballerinalang/packerina/cmd/NewCommandTest.java
test_class.identifier: NewCommandTest
test_class.superclass: extends CommandTest
test_case.body: @Test(description = "Test new command with help flag")
      public void testNewCommandWithHelp() throws IOException {
          // Test if no arguments was passed in
          String[] args = {"-h"};
          NewCommand newCommand = new NewCommand(tmpDir, printStream);
          new CommandLine(newCommand).parse(args);
          newCommand.execute();
  
          Assert.assertTrue(readOutput().contains("ballerina-new - Create a new Ballerina project at <project-path>"));
      }
test_case.class_method_signature: NewCommandTest.testNewCommandWithHelp()
test_case.full_signature: @Test(description = "Test new command with help flag") public void testNewCommandWithHelp()
test_case.identifier: testNewCommandWithHelp
test_case.invocations: parse execute assertTrue contains readOutput
test_case.modifiers: @Test(description = "Test new command with help flag") public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testNewCommandWithHelp()
focal_class.declarator: userDir
focal_class.modifier: private
focal_class.original_string: private Path userDir;
focal_class.type: Path
focal_class.var_name: userDir
focal_class.declarator: errStream
focal_class.modifier: private
focal_class.original_string: private PrintStream errStream;
focal_class.type: PrintStream
focal_class.var_name: errStream
focal_class.declarator: argList
focal_class.modifier: @CommandLine.Parameters
      private
focal_class.original_string: @CommandLine.Parameters
      private List<String> argList;
focal_class.type: List<String>
focal_class.var_name: argList
focal_class.declarator: helpFlag
focal_class.modifier: @CommandLine.Option(names = {"--help", "-h"}, hidden = true)
      private
focal_class.original_string: @CommandLine.Option(names = {"--help", "-h"}, hidden = true)
      private boolean helpFlag;
focal_class.type: boolean
focal_class.var_name: helpFlag
focal_class.file: cli/ballerina-packerina/src/main/java/org/ballerinalang/packerina/cmd/NewCommand.java
focal_class.identifier: NewCommand
focal_class.interfaces: implements BLauncherCmd
focal_class.class_method_signature: NewCommand.NewCommand()
focal_class.full_signature: public  NewCommand()
focal_class.identifier: NewCommand
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  NewCommand()
focal_class.class_method_signature: NewCommand.NewCommand(Path userDir, PrintStream errStream)
focal_class.full_signature: public  NewCommand(Path userDir, PrintStream errStream)
focal_class.identifier: NewCommand
focal_class.modifiers: public
focal_class.parameters: (Path userDir, PrintStream errStream)
focal_class.signature:  NewCommand(Path userDir, PrintStream errStream)
focal_class.class_method_signature: NewCommand.execute()
focal_class.full_signature: @Override public void execute()
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void execute()
focal_class.class_method_signature: NewCommand.getName()
focal_class.full_signature: @Override public String getName()
focal_class.identifier: getName
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getName()
focal_class.class_method_signature: NewCommand.printLongDesc(StringBuilder out)
focal_class.full_signature: @Override public void printLongDesc(StringBuilder out)
focal_class.identifier: printLongDesc
focal_class.modifiers: @Override public
focal_class.parameters: (StringBuilder out)
focal_class.return: void
focal_class.signature: void printLongDesc(StringBuilder out)
focal_class.class_method_signature: NewCommand.printUsage(StringBuilder out)
focal_class.full_signature: @Override public void printUsage(StringBuilder out)
focal_class.identifier: printUsage
focal_class.modifiers: @Override public
focal_class.parameters: (StringBuilder out)
focal_class.return: void
focal_class.signature: void printUsage(StringBuilder out)
focal_class.class_method_signature: NewCommand.setParentCmdParser(CommandLine parentCmdParser)
focal_class.full_signature: @Override public void setParentCmdParser(CommandLine parentCmdParser)
focal_class.identifier: setParentCmdParser
focal_class.modifiers: @Override public
focal_class.parameters: (CommandLine parentCmdParser)
focal_class.return: void
focal_class.signature: void setParentCmdParser(CommandLine parentCmdParser)
focal_method.body: @Override
      public void execute() {
          // If help flag is given print the help message.
          if (helpFlag) {
              String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(NEW_COMMAND);
              errStream.println(commandUsageInfo);
              return;
          }
          // Check if the project name is given
          if (null == argList) {
              CommandUtil.printError(errStream,
                      "The following required arguments were not provided:\n" +
                           "    <project-name>",
                      "ballerina new <project-name>",
                      true);
              return;
          }
          // Check if one argument is given and not more than one argument.
          if (!(1 == argList.size())) {
              CommandUtil.printError(errStream,
                      "too many arguments.",
                      "ballerina new <project-name>",
                      true);
              return;
          }
  
          Path path = userDir.resolve(argList.get(0));
          // Check if the directory or file exists with the given project name
          if (Files.exists(path)) {
              CommandUtil.printError(errStream,
                      "destination '" + path.toString() + "' already exists",
                      "ballerina new <project-name>",
                      true);
              return;
          }
  
          // Check if the command is executed inside a ballerina project
          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.");
      }
focal_method.class_method_signature: NewCommand.execute()
focal_method.full_signature: @Override public void execute()
focal_method.identifier: execute
focal_method.invocations: getCommandUsageInfo println printError size printError resolve get exists printError toString findProjectRoot printError toString createDirectories initProject println println getMessage println relativize println println println println
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void execute()