Skip to content

Commit

Permalink
Boolean values are now interpreted as flag options (no values)
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Aug 28, 2013
1 parent b664d64 commit 7d8e3dd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jboss.forge.addon.convert.ConverterFactory;
import org.jboss.forge.addon.shell.util.ShellUtil;
import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.ManyValued;
import org.jboss.forge.addon.ui.input.SingleValued;
Expand Down Expand Up @@ -55,8 +56,8 @@ public CommandLineParser generateParser(UICommand command,
{
Object defaultValue = InputComponents.getValueFor(input);
boolean isMultiple = input instanceof ManyValued;
// boolean hasValue = (InputComponents.getInputType(input) != InputType.CHECKBOX && !Boolean.class
// .isAssignableFrom(input.getValueType()));
boolean hasValue = (InputComponents.getInputType(input) != InputType.CHECKBOX && !Boolean.class
.isAssignableFrom(input.getValueType()));
try
{
OptionBuilder optionBuilder = new OptionBuilder();
Expand All @@ -65,7 +66,7 @@ public CommandLineParser generateParser(UICommand command,
.addDefaultValue(defaultValue == null ? null : defaultValue.toString())
.description(input.getLabel())
.hasMultipleValues(isMultiple)
// .hasValue(hasValue)
.hasValue(hasValue)
.required(input.isRequired());

if (input.getShortName() != InputComponents.DEFAULT_SHORT_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ public static CompletionStrategy getCompletionFor(InputComponent<?, Object> comp
CompletionStrategy strategy = null;
if (inputType == InputType.FILE_PICKER)
{
strategy = new FileInputCompletionStrategy(false);
strategy = FileInputCompletionStrategy.FILE;
}
else if (inputType == InputType.DIRECTORY_PICKER)
{
strategy = new FileInputCompletionStrategy(true);
strategy = FileInputCompletionStrategy.DIRECTORY;
}
if (component instanceof SelectComponent)
else if (inputType == InputType.CHECKBOX || Boolean.class
.isAssignableFrom(component.getValueType()))
{
strategy = new SelectComponentCompletionStrategy();
strategy = NoopCompletionStrategy.INSTANCE;
}
else if (component instanceof SelectComponent)
{
strategy = SelectComponentCompletionStrategy.INSTANCE;
}
// Always try UICompleter first and then fallback to the chosen strategy
strategy = new UICompleterCompletionStrategy(strategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import org.jboss.forge.addon.ui.util.InputComponents;
import org.jboss.forge.furnace.util.OperatingSystemUtils;

class FileInputCompletionStrategy implements CompletionStrategy
enum FileInputCompletionStrategy implements CompletionStrategy
{
DIRECTORY(true), FILE(false);

private final boolean directory;

public FileInputCompletionStrategy(boolean directory)
private FileInputCompletionStrategy(boolean directory)
{
this.directory = directory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.shell.aesh.completion;

import org.jboss.aesh.complete.CompleteOperation;
import org.jboss.forge.addon.convert.ConverterFactory;
import org.jboss.forge.addon.shell.ui.ShellContext;
import org.jboss.forge.addon.ui.input.InputComponent;

/**
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
enum NoopCompletionStrategy implements CompletionStrategy
{
INSTANCE;

@Override
public void complete(CompleteOperation completeOperation, InputComponent<?, Object> input, ShellContext context,
String typedValue, ConverterFactory converterFactory)
{
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
class SelectComponentCompletionStrategy implements CompletionStrategy
enum SelectComponentCompletionStrategy implements CompletionStrategy
{
INSTANCE;

@SuppressWarnings("unchecked")
@Override
Expand Down

0 comments on commit 7d8e3dd

Please sign in to comment.