Skip to content
Permalink
Browse files
adding @EXIT
  • Loading branch information
Romain Manni-Bucau committed Nov 30, 2015
1 parent 0ab8285 commit 68bbcb9617cb2da1ae4b2e026f92374529f9731c
Showing 2 changed files with 43 additions and 0 deletions.
@@ -21,6 +21,7 @@
import io.airlift.airline.ParseException;
import org.apache.batchee.cli.command.Abandon;
import org.apache.batchee.cli.command.Executions;
import org.apache.batchee.cli.command.Exit;
import org.apache.batchee.cli.command.Instances;
import org.apache.batchee.cli.command.Names;
import org.apache.batchee.cli.command.Restart;
@@ -86,6 +87,16 @@ public static void main(final String[] args) {
parser.parse(args).run();
} catch (final ParseException e) {
parser.parse("help").run();
} catch (final RuntimeException e) {
Class<?> current = e.getClass();
while (current != null) {
final Exit annotation = current.getAnnotation(Exit.class);
if (annotation != null) {
System.exit(annotation.value());
}
current = current.getSuperclass();
}
throw e;
}
}

@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.batchee.cli.command;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
@Target(TYPE)
public @interface Exit {
/**
* @return the exit code to use.
*/
int value();
}

0 comments on commit 68bbcb9

Please sign in to comment.