001/* 002 * Portions of this software was developed by employees of the National Institute 003 * of Standards and Technology (NIST), an agency of the Federal Government and is 004 * being made available as a public service. Pursuant to title 17 United States 005 * Code Section 105, works of NIST employees are not subject to copyright 006 * protection in the United States. This software may be subject to foreign 007 * copyright. Permission in the United States and in foreign countries, to the 008 * extent that NIST may hold copyright, to use, copy, modify, create derivative 009 * works, and distribute this software and its documentation without fee is hereby 010 * granted on a non-exclusive basis, provided that this notice and disclaimer 011 * of warranty appears in all copies. 012 * 013 * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER 014 * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY 015 * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF 016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM 017 * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE 018 * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT 019 * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, 020 * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, 021 * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, 022 * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR 023 * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT 024 * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. 025 */ 026 027package gov.nist.secauto.oscal.tools.cli.core; 028 029import gov.nist.secauto.metaschema.cli.processor.CLIProcessor; 030import gov.nist.secauto.metaschema.cli.processor.ExitStatus; 031import gov.nist.secauto.metaschema.model.MetaschemaVersion; 032import gov.nist.secauto.metaschema.model.common.util.IVersionInfo; 033import gov.nist.secauto.metaschema.model.common.util.MetaschemaJavaVersion; 034import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; 035import gov.nist.secauto.oscal.lib.LibOscalVersion; 036import gov.nist.secauto.oscal.lib.OscalVersion; 037import gov.nist.secauto.oscal.tools.cli.core.commands.assessmentplan.AssessmentPlanCommand; 038import gov.nist.secauto.oscal.tools.cli.core.commands.assessmentresults.AssessmentResultsCommand; 039import gov.nist.secauto.oscal.tools.cli.core.commands.catalog.CatalogCommand; 040import gov.nist.secauto.oscal.tools.cli.core.commands.componentdefinition.ComponentDefinitionCommand; 041import gov.nist.secauto.oscal.tools.cli.core.commands.metaschema.MetaschemaCommand; 042import gov.nist.secauto.oscal.tools.cli.core.commands.poam.PlanOfActionsAndMilestonesCommand; 043import gov.nist.secauto.oscal.tools.cli.core.commands.profile.ProfileCommand; 044import gov.nist.secauto.oscal.tools.cli.core.commands.ssp.SystemSecurityPlanCommand; 045 046import java.util.List; 047 048import edu.umd.cs.findbugs.annotations.NonNull; 049 050@SuppressWarnings("PMD.ShortClassName") 051public final class CLI { 052 public static void main(String[] args) { 053 System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager"); 054 055 ExitStatus status = runCli(args); 056 int exitCode = status.getExitCode().getStatusCode(); 057 System.exit(exitCode); 058 } 059 060 @NonNull 061 public static ExitStatus runCli(String... args) { 062 List<IVersionInfo> versions = ObjectUtils.notNull( 063 List.of( 064 new OscalCliVersion(), 065 new LibOscalVersion(), 066 new OscalVersion(), 067 new MetaschemaJavaVersion(), 068 new MetaschemaVersion())); 069 CLIProcessor processor = new CLIProcessor("oscal-cli", versions); 070 processor.addCommandHandler(new CatalogCommand()); 071 processor.addCommandHandler(new ProfileCommand()); 072 processor.addCommandHandler(new ComponentDefinitionCommand()); 073 processor.addCommandHandler(new SystemSecurityPlanCommand()); 074 processor.addCommandHandler(new AssessmentPlanCommand()); 075 processor.addCommandHandler(new AssessmentResultsCommand()); 076 processor.addCommandHandler(new PlanOfActionsAndMilestonesCommand()); 077 processor.addCommandHandler(new MetaschemaCommand()); 078 return processor.process(args); 079 } 080 081 private CLI() { 082 // disable construction 083 } 084}