<commit_before>/***********************************************************************
* Copyright (c) 2013-2016 Commonwealth Computer Research, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at
* http://www.opensource.org/licenses/apache2.0.php.
*************************************************************************/

package org.locationtech.geomesa.tools.status

import com.beust.jcommander.{Parameter, ParameterException, Parameters}
import com.typesafe.config.{Config, ConfigRenderOptions}
import org.locationtech.geomesa.convert.ConverterConfigLoader
import org.locationtech.geomesa.tools.Command
import org.locationtech.geomesa.utils.geotools.{SimpleFeatureTypeLoader, SimpleFeatureTypes}
import org.opengis.feature.simple.SimpleFeatureType

class EnvironmentCommand extends Command {

  override val name = "env"
  override val params = new EnvironmentParameters()
  // TODO accumulo environment?
  override def execute(): Unit = {
    import scala.collection.JavaConversions._

    if (params.sfts == null && params.converters == null && !params.listSfts &&
      !params.listConverters && !params.describeSfts && !params.describeConverters) {
      throw new ParameterException("Specific environment was not provided")
    } else {
      if (params.listSfts) {
        listSftsNames()
      }
      if (params.listConverters){
        listConverterNames()
      }
      if (params.describeSfts) {
        listSfts()
      }
      if (params.describeConverters) {
        listConverters()
      }
      if (params.sfts != null) {
        listSfts(params.sfts.toList)
      }
      if (params.converters != null) {
        listConverters(params.converters.toList)
      }
    }
  }

  def listSfts(names: List[String] = List.empty): Unit = {
    val all = SimpleFeatureTypeLoader.sfts
    val filtered = if (names.isEmpty) all else names.flatMap(n => all.find(_.getTypeName == n))
    Command.output.info("Simple Feature Types:")<commit_msg>GEOMESA-1693 GeoMesa env command without arguments returns a poor error (#1389)<commit_after>/***********************************************************************
* Copyright (c) 2013-2016 Commonwealth Computer Research, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at
* http://www.opensource.org/licenses/apache2.0.php.
*************************************************************************/

package org.locationtech.geomesa.tools.status

import com.beust.jcommander.{Parameter, ParameterException, Parameters}
import com.typesafe.config.{Config, ConfigRenderOptions}
import org.locationtech.geomesa.convert.ConverterConfigLoader
import org.locationtech.geomesa.tools.Command
import org.locationtech.geomesa.utils.geotools.{SimpleFeatureTypeLoader, SimpleFeatureTypes}
import org.opengis.feature.simple.SimpleFeatureType

class EnvironmentCommand extends Command {

  override val name = "env"
  override val params = new EnvironmentParameters()
  // TODO accumulo environment?
  override def execute(): Unit = {
    import scala.collection.JavaConversions._

    if (params.sfts == null && params.converters == null && !params.listSfts &&
      !params.listConverters && !params.describeSfts && !params.describeConverters) {
      Command.output.info("No flags given; displaying list of SFTs and Converters.")
      Command.output.info(s"Use 'help $name' to see complete command options.")

      listSftsNames()
      listConverterNames()
    } else {
      if (params.listSfts) {
        listSftsNames()
      }
      if (params.listConverters){
        listConverterNames()
      }
      if (params.describeSfts) {
        listSfts()
      }
      if (params.describeConverters) {
        listConverters()
      }
      if (params.sfts != null) {
        listSfts(params.sfts.toList)
      }
      if (params.converters != null) {
        listConverters(params.converters.toList)
      }
    }
  }

  def listSfts(names: List[String] = List.empty): Unit = {
    val all = SimpleFeatureTypeLoader.sfts
    val filtered = if (names.isEmpty) all else names.flatMap(n => all.find(_.getTypeName == n))
    Command.output.info("Simple Feature Types:")
{'fraction_non_alphanumeric': 0.16164817749603805, 'fraction_numerical': 0.007244736246321032, 'mean_word_length': 3.892580287929125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '987679', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1191, 'n_words': 291}