All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bitbucket.bradleysmithllc.etlunit.cli.ProfileCmd Maven / Gradle / Ivy

package org.bitbucket.bradleysmithllc.etlunit.cli;

/*
 * #%L
 * etlunit-cli
 * %%
 * Copyright (C) 2010 - 2014 bradleysmithllc
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.bitbucket.bradleysmithllc.etlunit.maven.ETLUnitMojo;
import org.clamshellcli.api.Command;
import org.clamshellcli.api.Configurator;
import org.clamshellcli.api.Context;
import org.clamshellcli.api.IOConsole;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class ProfileCmd implements Command {
	private static final String NAMESPACE = "syscmd";
	public static final String ACTION_NAME = "profile";

	public Object execute(Context ctx) {
		IOConsole console = ctx.getIoConsole();

		String [] inputLine = (String []) ctx.getValue(Context.KEY_COMMAND_LINE_ARGS);

		if (inputLine == null || inputLine.length == 0)
		{
			console.writeOutput("Current etlunit configuration: " + Configurator.VALUE_LINE_SEP);
			for (String prof : ETLUnitMojo.getUserProfiles()) {
				console.writeOutput("\t" + prof + Configurator.VALUE_LINE_SEP);
			}

			ETLUnitMojo.setUserProfile(null);
			console.writeOutput("Etlunit configuration reset." + Configurator.VALUE_LINE_SEP);
		}
		else if (inputLine[0].equals("-l"))
		{
			console.writeOutput("Current etlunit configuration: " + Configurator.VALUE_LINE_SEP);
			for (String prof : ETLUnitMojo.getUserProfiles()) {
				console.writeOutput("\t" + prof + Configurator.VALUE_LINE_SEP);
			}
		}
		else
		{
			ETLUnitMojo.setUserProfile(inputLine[0]);

			console.writeOutput("Etlunit configuration changed to: " + Configurator.VALUE_LINE_SEP);
			for (String prof : ETLUnitMojo.getUserProfiles()) {
				console.writeOutput("\t" + prof + Configurator.VALUE_LINE_SEP);
			}
		}

		return null;
	}

	public Descriptor getDescriptor(){
		return new Descriptor() {
			public String getNamespace() {return NAMESPACE;}

			public String getName() {
				return ACTION_NAME;
			}

			public String getDescription() {
				return "Changes to a specific profile or colon-separated list of profiles.  Similar to using the etlunit configuration flag in maven (Not a maven profile).  Leave profile name blank to switch to the default.";
			}

			public String getUsage() {
				return "Type 'profile <-l> | ((:)*)?'";
			}

			public Map getArguments() {
				Map map = new HashMap();

				map.put("name", "Profile name or colon-separated list of names.  Blank to reset a previously selected profile.  Use -l to list effective profile(s) - but this cannot be used with other options.");

				return map;
			}
		};
	}

	@Override
	public void plug(Context context) {
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy