/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.cli;

import alluxio.Configuration;
import alluxio.PropertyKey;

import java.util.Map.Entry;

/**
 * Utility for printing Alluxio configuration.
 */
public final class GetConf {
  private static final String USAGE = "USAGE: GetConf [KEY]\n\n"
      + "GetConf [KEY] prints the configured value for the given key. If the key is invalid, the "
      + "exit code will be nonzero. If the key is valid but isn't set, an empty string is printed. "
      + "If no key is specified, all configuration is printed.";

  /**
   * @param args should be size 0 or 1; if size 1, the specified configuration value is printed,
   *        otherwise all configuration is printed
   */
  public static void main(String[] args) {
    switch (args.length) {
      case 0:
        for (Entry<String, String> entry : Configuration.toMap().entrySet()) {
          String key = entry.getKey();
          String value = entry.getValue();
          System.out.println(String.format("%s=%s", key, value));
        }
        break;
      case 1:
        if (!PropertyKey.isValid(args[0])) {
          System.out.println(String.format("%s is not a valid configuration key", args[0]));
          System.out.println(USAGE);
          System.exit(1);
        }
        PropertyKey key = PropertyKey.fromString(args[0]);
        if (!Configuration.containsKey(key)) {
          System.out.println("");
        } else {
          System.out.println(Configuration.get(key));
        }
        break;
      default:
        System.out.println(USAGE);
        System.exit(1);
    }
  }

  private GetConf() {} // this class is not intended for instantiation
}

@@ -588,16 +588,322 @@
 tyKey;%0A%0A
+import com.google.common.base.Preconditions;%0Aimport org.apache.commons.cli.CommandLine;%0Aimport org.apache.commons.cli.CommandLineParser;%0Aimport org.apache.commons.cli.DefaultParser;%0Aimport org.apache.commons.cli.Option;%0Aimport org.apache.commons.cli.Options;%0Aimport org.apache.commons.cli.ParseException;%0A%0A
 import j
@@ -1056,24 +1056,35 @@
 AGE: GetConf
+ %5B-inBytes%5D
  %5BKEY%5D%5Cn%5Cn%22%0A
@@ -1349,214 +1349,1023 @@
 ted.
-%22;%0A%0A  /**%0A   * @param args should be size 0 or 1; if size 1, the specified configuration value is printed,%0A   *        otherwise all configuration is printed%0A   */%0A  public static void main(String%5B%5D args) %7B
+ If %5C%22inBytes%5C%22 option is specified, %22%0A      + %22a value of %5C%221KB%5C%22 will be converted to a value of 1024.%22;%0A%0A  private static final String BYTES_OPTION_NAME = %22bytes%22;%0A  private static final Option BYTES_OPTION =%0A      Option.builder().required(false).longOpt(BYTES_OPTION_NAME).hasArg(false)%0A          .desc(%22value in bytes%22).build();%0A%0A  /**%0A   * @param args should be size 0 or 1; if size 1, the specified configuration value is printed,%0A   *        otherwise all configuration is printed%0A   */%0A  public static void main(String%5B%5D args) %7B%0A    Options opts = new Options().addOption(BYTES_OPTION);%0A    CommandLineParser parser = new DefaultParser();%0A    CommandLine cmd = null;%0A%0A    try %7B%0A      cmd = parser.parse(opts, args, true /* stopAtNonOption */);%0A    %7D catch (ParseException e) %7B%0A      System.err.println(%22Unable to parse input args: %22 + e.getMessage());%0A      System.out.println(USAGE);%0A      System.exit(1);%0A    %7D%0A    Preconditions.checkNotNull(cmd, %22Unable to parse input args%22);%0A    args = cmd.getArgs();
 %0A   
@@ -2950,17 +2950,16 @@
     if (
-!
 Configur
@@ -2998,32 +2998,111 @@
     
-System.out.println(%22%22
+if (cmd.hasOption(BYTES_OPTION_NAME)) %7B%0A            System.out.println(Configuration.getBytes(key)
 );%0A
+  
     
@@ -3114,16 +3114,18 @@
  else %7B%0A
+  
         
@@ -3162,32 +3162,95 @@
 tion.get(key));%0A
+          %7D%0A        %7D else %7B%0A          System.out.println(%22%22);%0A
         %7D%0A      

Add support for getConf to parse value as bytes