/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package tachyon.shell.command;

import java.io.IOException;

import tachyon.TachyonURI;
import tachyon.client.file.TachyonFileSystem;
import tachyon.client.file.options.MkdirOptions;
import tachyon.conf.TachyonConf;
import tachyon.exception.TachyonException;

/**
 * Creates a new directory specified by the path in args, including any parent folders that are
 * required. This command fails if a directory or file with the same path already exists.
 */
public final class MkdirCommand extends AbstractTfsShellCommand {

  /**
   * Constructs a new instance to create a new directory.
   *
   * @param conf the configuration for Tachyon
   * @param tfs the filesystem of Tachyon
   */
  public MkdirCommand(TachyonConf conf, TachyonFileSystem tfs) {
    super(conf, tfs);
  }

  @Override
  public String getCommandName() {
    return "mkdir";
  }

  @Override
  protected int getNumOfArgs() {
    return 1;
  }

  @Override
  public void run(String... args) throws IOException {
    TachyonURI inputPath = new TachyonURI(args[0]);

    try {
      MkdirOptions options = new MkdirOptions.Builder(mTachyonConf).setRecursive(true).build();
      mTfs.mkdir(inputPath, options);
      System.out.println("Successfully created directory " + inputPath);
    } catch (TachyonException e) {
      throw new IOException(e.getMessage());
    }
  }

  @Override
  public String getUsage() {
    return "mkdir <path>";
  }

  @Override
  public String getDescription() {
    return "Creates the specified directory, including any parent directories that are required.";
  }
}

@@ -1766,16 +1766,49 @@
 ption %7B%0A
+    for (String path : args) %7B%0A  
     Tach
@@ -1845,19 +1845,18 @@
 URI(
-args%5B0%5D
+path
 );%0A%0A
+  
     
@@ -1861,16 +1861,18 @@
   try %7B%0A
+  
       Mk
@@ -1965,16 +1965,18 @@
 ;%0A      
+ 
+ 
 mTfs.mkd
@@ -1999,16 +1999,18 @@
 tions);%0A
+  
       Sy
@@ -2078,16 +2078,18 @@
 h);%0A    
+ 
+ 
 %7D catch 
@@ -2107,24 +2107,26 @@
 eption e) %7B%0A
+  
       throw 
@@ -2158,16 +2158,24 @@
 age());%0A
+      %7D%0A
     %7D%0A  
@@ -2245,9 +2245,30 @@
 path
-%3E
+1%3E %5Bpath2%5D ... %5Bpathn%5D
 %22;%0A 
@@ -2360,17 +2360,19 @@
 director
-y
+ies
 , includ
@@ -2422,11 +2422,268 @@
 d.%22;%0A  %7D
+%0A%0A  @Override%0A  public boolean validateArgs(String... args) %7B%0A    boolean valid = args.length %3E= getNumOfArgs();%0A    if (!valid) %7B%0A      System.out.println(getCommandName() + %22 takes %22 + getNumOfArgs() + %22 arguments at least%5Cn%22);%0A    %7D%0A    return valid;%0A  %7D
 %0A%7D%0A

Improve tfs mkdir shell command to process multiple args