Skip to content

Instantly share code, notes, and snippets.

@stalep
Last active December 11, 2015 23:28
Show Gist options
  • Save stalep/4676928 to your computer and use it in GitHub Desktop.
Save stalep/4676928 to your computer and use it in GitHub Desktop.
public interface UICommand
{
public UICommandID getId();
public void initializeUI(UIContext context) throws Exception;
public void validate(UIValidationContext context);
public Result execute(UIContext context) throws Exception;
//leaning TOWARDS list<string>
//public List<UIInpu<?>t> complete(UIInput<?> value);
public List<String> complete(UIInput<?> value);
}
public class FooCommand implements UICommand
{
@Inject
private UIInput<File> f1;
@Inject
private UIInput<String> f2;
@Inject
private UIInput<List<File>> arguments;
@Override
public UICommandID getId()
{
return new SimpleUICommandID("foo", "Do some foo");
}
@Override
public void initializeUI(UIContext context) throws Exception
{
f1.setLabel("config-file");
f1.setRequired(true);
context.getUIBuilder().add(f1);
f2.setLabel("value");
f2.setRequired(false);
context.getUIBuilder().add(f2);
arguments.setLabel(""); //no labal means its an argument afaik
arguments.setRequired(true);
context.getUIBuilder().add(arguments);
}
@Override
public void validate(UIValidationContext context)
{
}
@Override
public Result execute(UIContext context) throws Exception
{
//ignore result for now
return Results.success("boo");
}
//I would argue that List<String> would be easier for the user, but List<UIInput<?>> will also work
//public List<UIInput<?>> complete(UIInput<?> value) {
public List<String> complete(UIInput<?> value)
if(value.getName().equals(f1.getName())
return configFileCompletion(value.getValue());
else if(value.getName().equals(f2.getName())
return valueCompletion(value.getValue());
else if(value.getName().equals(arguments.getName())
return argumentsCompletion(value.getValue());
else
return null;
}
private List<String> configFileCompletion(String configValue) {
//blabla
}
...
private List<String> argumentsCompletion(List<File> configValue) {
//this would not be needed in the final version as æsh would
//recognize arguments set as Files and use the "default" filehandler.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment