001/*
002 * Copyright (c) 2012-2021 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License 2.0 which is available at
006 * http://www.eclipse.org/legal/epl-2.0.
007 *
008 * SPDX-License-Identifier: EPL-2.0
009 */
010
011package org.eclipse.golo.cli.command;
012
013import com.beust.jcommander.Parameter;
014import com.beust.jcommander.Parameters;
015import com.beust.jcommander.ParametersDelegate;
016import com.beust.jcommander.converters.FileConverter;
017
018import java.io.File;
019import java.util.LinkedList;
020import java.util.List;
021
022import org.eclipse.golo.cli.command.spi.CliCommand;
023import org.eclipse.golo.compiler.GoloCompiler;
024import org.eclipse.golo.cli.GoloFilesManager;
025
026import static gololang.Messages.*;
027
028@Parameters(commandNames = "check", resourceBundle = "commands", commandDescriptionKey = "check")
029public final class CheckCommand implements CliCommand {
030
031  @Parameter(names = "--exit", descriptionKey = "check.exit")
032  boolean exit = false;
033
034  @Parameter(names = "--verbose", descriptionKey = "verbose")
035  boolean verbose = false;
036
037  @Parameter(descriptionKey = "source_files", converter = FileConverter.class)
038  List<File> files = new LinkedList<>();
039
040  @ParametersDelegate
041  ClasspathOption classpath = new ClasspathOption();
042
043  @Override
044  public boolean verbose() {
045    return this.verbose;
046  }
047
048  @Override
049  public void execute() throws Throwable {
050    GoloCompiler compiler = classpath.initGoloClassLoader().getCompiler();
051    GoloFilesManager.goloFiles(this.files)
052      .forEach(wrappedAction(this.exit, file -> {
053        if (this.verbose) {
054          info(message("check_info", file.getAbsolutePath()));
055        }
056        compiler.resetExceptionBuilder();
057        compiler.check(compiler.parse(file));
058      }));
059  }
060}
061