001/* 002 * SPDX-License-Identifier: Apache-2.0 003 * 004 * Copyright 2020-2024 Andres Almiray. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.kordamp.maven.checker.cli; 019 020import picocli.CommandLine; 021 022import java.io.PrintWriter; 023 024/** 025 * @author Andres Almiray 026 * @since 1.1.0 027 */ 028@CommandLine.Command(name = "pomchecker", 029 description = "pomchecker", 030 mixinStandardHelpOptions = true, 031 versionProvider = Versions.class, 032 subcommands = {CheckBom.class, CheckMavenCentral.class}) 033public class Main extends BaseCommand implements Runnable, IO { 034 private PrintWriter out; 035 private PrintWriter err; 036 037 @Override 038 public PrintWriter getOut() { 039 return out; 040 } 041 042 @Override 043 public void setOut(PrintWriter out) { 044 this.out = out; 045 } 046 047 @Override 048 public PrintWriter getErr() { 049 return err; 050 } 051 052 @Override 053 public void setErr(PrintWriter err) { 054 this.err = err; 055 } 056 057 public void run() { 058 Banner.display(err); 059 060 spec.commandLine().usage(out); 061 } 062 063 public static void main(String[] args) { 064 System.exit(run(args)); 065 } 066 067 public static int run(String... args) { 068 Main cmd = new Main(); 069 CommandLine commandLine = new CommandLine(cmd); 070 cmd.out = commandLine.getOut(); 071 cmd.err = commandLine.getErr(); 072 return execute(commandLine, args); 073 } 074 075 public static int run(PrintWriter out, PrintWriter err, String... args) { 076 Main cmd = new Main(); 077 CommandLine commandLine = new CommandLine(cmd); 078 commandLine.setOut(out); 079 commandLine.setErr(err); 080 cmd.out = out; 081 cmd.err = err; 082 return execute(commandLine, args); 083 } 084 085 private static int execute(CommandLine commandLine, String[] args) { 086 return commandLine.execute(args); 087 } 088}