/******************************************************************************* * Copyright (c) 2012 Arapiki Solutions Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * "Peter Smith <psmith@arapiki.com>" - initial API and * implementation and/or initial documentation *******************************************************************************/ package com.buildml.main.commands; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Options; import com.buildml.main.CliUtils; import com.buildml.main.ICliCommand; import com.buildml.model.IBuildStore; import com.buildml.model.IPackageRootMgr; import com.buildml.utils.errors.ErrorCode; /** * BuildML CLI Command class that implements the "set-bml-depth" command. * * @author "Peter Smith <psmith@arapiki.com>" */ public class CliCommandSetBuildMLFileDepth implements ICliCommand { /*=====================================================================================* * PUBLIC METHODS *=====================================================================================*/ /* (non-Javadoc) * @see com.buildml.main.ICliCommand#getLongDescription() */ @Override public String getLongDescription() { return CliUtils.genLocalizedMessage("#include commands/set-bml-depth.txt"); } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.ICliCommand#getName() */ @Override public String getName() { return "set-bml-depth"; } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.ICliCommand#getOptions() */ @Override public Options getOptions() { return new Options(); } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.ICliCommand#getParameterDescription() */ @Override public String getParameterDescription() { return "<depth>"; } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.ICliCommand#getShortDescription() */ @Override public String getShortDescription() { return "Set the distance between build.bml and @workspace"; } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.ICliCommand#processOptions(org.apache.commons.cli.CommandLine) */ @Override public void processOptions(IBuildStore buildStore, CommandLine cmdLine) { /* no options */ } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.ICliCommand#invoke(com.buildml.model.BuildStore, java.lang.String[]) */ @Override public void invoke(IBuildStore buildStore, String buildStorePath, String[] args) { CliUtils.validateArgs(getName(), args, 1, 1, "You must specify a numeric distance."); IPackageRootMgr pkgRootMgr = buildStore.getPackageRootMgr(); String depthString = args[0]; int depth = 0; try { depth = Integer.valueOf(depthString); } catch (NumberFormatException ex) { CliUtils.reportErrorAndExit("Depth value: " + depthString + " is not a valid integer."); } /* set the BuildML file depth */ int rc = pkgRootMgr.setBuildMLFileDepth(depth); if (rc == ErrorCode.BAD_PATH) { CliUtils.reportErrorAndExit("Invalid BuildML file depth: " + depth); } System.out.println("BuildML file depth set to " + depth + "."); } /*-------------------------------------------------------------------------------------*/ }