/*
 * Licensed to the Apache Software Foundation (ASF) 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 org.apache.accumulo.shell.commands;

import java.io.IOException;

import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.shell.Shell;
import org.apache.accumulo.shell.Shell.Command;
import org.apache.commons.cli.CommandLine;

public class ImportDirectoryCommand extends Command {

  @Override
  public String description() {
    return "bulk imports an entire directory of data files to the current"
        + " table. The boolean argument determines if accumulo sets the time.";
  }

  @Override
  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
      throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
    shellState.checkTableState();

    String dir = cl.getArgs()[0];
    String failureDir = cl.getArgs()[1];
    final boolean setTime = Boolean.parseBoolean(cl.getArgs()[2]);

    shellState.getConnector().tableOperations().importDirectory(shellState.getTableName(), dir,
        failureDir, setTime);
    return 0;
  }

  @Override
  public int numArgs() {
    return 3;
  }

  @Override
  public String usage() {
    return getName() + " <directory> <failureDirectory> true|false";
  }

}

@@ -1048,32 +1048,94 @@
 FoundException;%0A
+import org.apache.accumulo.core.client.admin.TableOperations;%0A
 import org.apach
@@ -1501,16 +1501,160 @@
 he time.
+ %22%0A        + %22Passing 3 arguments will use the old bulk import.  The new bulk import only takes 2 %22%0A        + %22arguments: %3Cdirectory%3E true%7Cfalse
 %22;%0A  %7D%0A%0A
@@ -1900,20 +1900,23 @@
   String
- dir
+%5B%5D args
  = cl.ge
@@ -1926,11 +1926,8 @@
 gs()
-%5B0%5D
 ;%0A  
@@ -1939,21 +1939,151 @@
 ing 
-failureDir = 
+dir = args%5B0%5D;%0A    boolean setTime;%0A%0A    // new bulk import only takes 2 args%0A    if (args.length == 2) %7B%0A      setTime = Boolean.parseBoolean(
 cl.g
@@ -2097,27 +2097,532 @@
 )%5B1%5D
+)
 ;%0A    
+  
-final boolean
+TableOperations.ImportExecutorOptions bulk = shellState.getConnector().tableOperations()%0A          .addFilesTo(shellState.getTableName()).from(dir);%0A      if (setTime)%0A        bulk.settingLogicalTime().load();%0A      else%0A        bulk.load();%0A    %7D else if (args.length == 3) %7B%0A      // warn using deprecated bulk import%0A      Shell.log.warn(%0A          %22Deprecated since 2.0.0. New bulk import technique does not take a failure directory %22%0A              + %22as an argument.%22);%0A      String failureDir = args%5B1%5D;%0A     
  set
@@ -2667,17 +2667,18 @@
 ()%5B2%5D);%0A
-%0A
+  
     shel
@@ -2773,16 +2773,18 @@
         
+ 
+ 
 failureD
@@ -2797,16 +2797,275 @@
 tTime);%0A
+      return 0;%0A    %7D else %7B%0A      shellState.printException(%0A          new IllegalArgumentException(String.format(%22Expected 2 or 3 arguments. There %25s %25d.%22,%0A              args.length == 1 ? %22was%22 : %22were%22, args.length)));%0A      printHelp(shellState);%0A    %7D%0A%0A
     retu
@@ -3123,17 +3123,47 @@
  return 
-3
+Shell.NO_FIXED_ARG_LENGTH_CHECK
 ;%0A  %7D%0A%0A 
@@ -3236,17 +3236,17 @@
 ectory%3E 
-%3C
+%5B
 failureD
@@ -3245,33 +3245,33 @@
 failureDirectory
-%3E
+%5D
  true%7Cfalse%22;%0A  

Update Shell bulk import command. Closes #470