/*
 * 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 javax.annotation.concurrent.ThreadSafe;

import tachyon.TachyonURI;
import tachyon.client.file.FileSystem;
import tachyon.conf.TachyonConf;

/**
 * Changes the group of a file or directory specified by args.
 */
@ThreadSafe
public final class ChgrpCommand extends AbstractAclCommand {

  /**
   * Creates a new instance of {@link ChgrpCommand}.
   *
   * @param conf a Tachyon configuration
   * @param fs a Tachyon file system handle
   */
  public ChgrpCommand(TachyonConf conf, FileSystem fs) {
    super(conf, fs);
  }

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

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

  @Override
  public void run(String... args) throws IOException {
    String group = args[0];
    TachyonURI path = new TachyonURI(args[1]);
    chgrp(path, group, false);
  }

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

  @Override
  public String getDescription() {
    return "Changes the group of a file or directory specified by args.";
  }
}

@@ -895,16 +895,237 @@
 dSafe;%0A%0A
+import org.apache.commons.cli.BasicParser;%0Aimport org.apache.commons.cli.CommandLine;%0Aimport org.apache.commons.cli.CommandLineParser;%0Aimport org.apache.commons.cli.Options;%0Aimport org.apache.commons.cli.ParseException;%0A%0A
 import t
@@ -1143,16 +1143,16 @@
 yonURI;%0A
-
 import t
@@ -1802,16 +1802,394 @@
 ption %7B%0A
+    CommandLineParser parser = new BasicParser();%0A    Options options = new Options();%0A    // Add R option or chgrp recursively.%0A    options.addOption(%22R%22, false, %22recursively%22);%0A    CommandLine cmd;%0A    try %7B%0A      cmd = parser.parse(options, args);%0A    %7D catch (ParseException e) %7B%0A      System.err.println(%22Unable to parse input args%22 + e.getMessage());%0A      return;%0A    %7D%0A%0A
     Stri
@@ -2199,20 +2199,29 @@
 group = 
-a
+cmd.getA
 rgs
+()
 %5B0%5D;%0A   
@@ -2258,18 +2258,28 @@
 URI(
-a
+cmd.getA
 rgs
+()
 %5B1%5D);%0A
+%0A
     
@@ -2297,21 +2297,34 @@
  group, 
-false
+cmd.hasOption(%22R%22)
 );%0A  %7D%0A%0A
@@ -2381,16 +2381,21 @@
 n %22chgrp
+ %5B-R%5D
  %3Cgroup%3E
@@ -2452,24 +2452,24 @@
 ription() %7B%0A
-
     return %22
@@ -2533,11 +2533,267 @@
 s.%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 argument at least%5Cn%22);%0A    %7D%0A    return valid;%0A  %7D
 %0A%7D%0A

Add -R option in chgrp.