2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
19 package org.apache.karaf.tooling.commands;
21 import java.lang.annotation.Annotation;
22 import java.lang.reflect.Field;
24 import org.apache.karaf.shell.api.action.Action;
25 import org.apache.karaf.shell.api.action.Argument;
27 public abstract class AbstractCommandHelpPrinter implements CommandHelpPrinter {
29 protected Argument replaceDefaultArgument(Field field, Argument argument) {
30 if (Argument.DEFAULT.equals(argument.name())) {
31 final Argument delegate = argument;
32 final String name = field.getName();
33 argument = new Argument() {
34 public String name() {
38 public String description() {
39 return delegate.description();
42 public boolean required() {
43 return delegate.required();
47 return delegate.index();
50 public boolean multiValued() {
51 return delegate.multiValued();
54 public String valueToShowInHelp() {
55 return delegate.valueToShowInHelp();
58 public Class<? extends Annotation> annotationType() {
59 return delegate.annotationType();
66 protected Object getDefaultValue(Action action, Field field) {
68 field.setAccessible(true);
69 return field.get(action);
70 } catch (Exception e) {
75 protected String getDefaultValueString(Object o) {
77 && (!(o instanceof Boolean) || ((Boolean) o))
78 && (!(o instanceof Number) || ((Number) o).doubleValue() != 0.0)) {