org.ow2.petals.cli.command.Exit Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2010-2012 EBM WebSourcing, 2012-2023 Linagora
*
* This program/library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at your
* option) any later version.
*
* This program/library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program/library; If not, see http://www.gnu.org/licenses/
* for the GNU Lesser General Public License version 2.1.
*/
package org.ow2.petals.cli.command;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.ow2.petals.cli.api.command.AbstractCommand;
import org.ow2.petals.cli.api.command.CommandUtil;
import org.ow2.petals.cli.api.command.exception.CommandException;
import org.ow2.petals.cli.api.command.exception.CommandTooManyArgumentsException;
import org.ow2.petals.cli.api.command.exception.CommandUnparsableArgumentException;
/**
* This command exits the current shell with an exit code.
* @author Sebastien Andre - EBM WebSourcing
* @author Alexandre Lagane - Linagora
*/
public class Exit extends AbstractCommand {
public Exit() {
super();
this.setUsage(CommandUtil.formatCommandUsage(this));
this.setDescription("Exit this shell");
}
/**
* {@inheritDoc}
*
*
* Dedicated processing to the command 'exit': No connection is required to
* execute it.
*
*/
@Override
public boolean isConnectionRequired(CommandLine cli) {
return false;
}
@Override
public Options createOptions() {
return new Options();
}
@Override
public void doExecute(CommandLine cli, final String... args) throws CommandException {
if (!this.checkArguments(args, 0, 1)) {
throw new CommandTooManyArgumentsException(this, args);
}
try {
final int status = args.length > 0 ? Integer.parseInt(args[0]) : 0;
this.getShell().exit(status);
} catch (final NumberFormatException e) {
throw new CommandUnparsableArgumentException(this, args[0]);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy