@Override
  @SuppressWarnings("unchecked")
  public int run() throws IOException {
    Preconditions.checkArgument(targets != null && targets.size() == 1, "Parquet file is required.");

    if (targets.size() > 1) {
      Preconditions.checkArgument(outputPath == null, "Cannot output multiple schemas to file %s", outputPath);
      for (String source : targets) {
        console.info("{}: {}", source, getSchema(source));
      }
    } else {
      String source = targets.get(0);

      if (outputPath != null) {
        try (OutputStream out = overwrite ? create(outputPath) : createWithNoOverwrite(outputPath)) {
          out.write(getSchema(source).getBytes(StandardCharsets.UTF_8));
        }
      } else {
        console.info(getSchema(source));
      }
    }

    return 0;
  }
@Test
  public void testSchemaCommandOverwriteExistentFile() throws IOException {
    File inputFile = parquetFile();
    File outputFile = new File(getTempFolder(), getClass().getSimpleName() + ".avsc");
    FileUtils.touch(outputFile);
    Assert.assertEquals(0, outputFile.length());
    SchemaCommand command = new SchemaCommand(createLogger());
    command.targets = Arrays.asList(inputFile.getAbsolutePath());
    command.outputPath = outputFile.getAbsolutePath();
    command.overwrite = true;
    command.setConf(new Configuration());
    Assert.assertEquals(0, command.run());
    Assert.assertTrue(0 < outputFile.length());
  }