Skip to content

Commit

Permalink
Updated to Aesh 0.43 and implemented ManProvider API
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Nov 15, 2013
1 parent 5e6ff52 commit b242333
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public AbstractShellInteraction findCommand(ShellContext shellContext, String co
return result;
}

private String getCommandName(ShellContext shellContext, UICommand cmd)
public String getCommandName(ShellContext shellContext, UICommand cmd)
{
return ShellUtil.shellifyName(cmd.getMetadata(shellContext).getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import javax.inject.Inject;

import org.jboss.aesh.console.helper.ManProvider;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.forge.addon.resource.FileResource;
import org.jboss.forge.addon.resource.ResourceFactory;
Expand All @@ -29,25 +28,23 @@ public class ShellFactoryImpl implements ShellFactory
private final ResourceFactory resourceFactory;
private final AddonRegistry addonRegistry;
private final CommandManager commandManager;
private final ManProvider manProvider;

@Inject
public ShellFactoryImpl(AddonRegistry addonRegistry, CommandManager commandManager,
ResourceFactory resourceFactory, ManProvider manProvider)
ResourceFactory resourceFactory)
{
super();
this.addonRegistry = addonRegistry;
this.commandManager = commandManager;
this.resourceFactory = resourceFactory;
this.manProvider = manProvider;
}

@Override
public Shell createShell(File initialSelection, Settings settings)
{
Assert.notNull(settings, "Settings cannot be null");
FileResource<?> initialResource = resourceFactory.create(initialSelection).reify(FileResource.class);
return new ShellImpl(initialResource, settings, commandManager, addonRegistry, manProvider);
return new ShellImpl(initialResource, settings, commandManager, addonRegistry);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.jboss.aesh.console.Console;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.helper.InterruptHook;
import org.jboss.aesh.console.helper.ManProvider;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.aesh.console.settings.SettingsBuilder;
import org.jboss.aesh.terminal.CharacterType;
Expand All @@ -27,6 +26,7 @@
import org.jboss.forge.addon.resource.FileResource;
import org.jboss.forge.addon.shell.aesh.AbstractShellInteraction;
import org.jboss.forge.addon.shell.aesh.ForgeCommandRegistry;
import org.jboss.forge.addon.shell.aesh.ForgeManProvider;
import org.jboss.forge.addon.shell.ui.ShellContextImpl;
import org.jboss.forge.addon.shell.ui.ShellUIOutputImpl;
import org.jboss.forge.addon.ui.CommandExecutionListener;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class ShellImpl implements Shell
private final UIOutput output;

public ShellImpl(FileResource<?> initialResource, Settings settings, CommandManager commandManager,
AddonRegistry addonRegistry, ManProvider manProvider)
AddonRegistry addonRegistry)
{
this.currentResource = initialResource;
this.addonRegistry = addonRegistry;
Expand All @@ -70,11 +70,11 @@ public void handleInterrupt(Console console)
}
}).create();
this.console = new AeshConsoleBuilder()
.prompt(createPrompt())
.settings(newSettings)
.commandRegistry(new ForgeCommandRegistry(this, commandManager))
.manProvider(manProvider)
.create();
.prompt(createPrompt())
.settings(newSettings)
.commandRegistry(new ForgeCommandRegistry(this, commandManager))
.manProvider(new ForgeManProvider(this, commandManager))
.create();
this.output = new ShellUIOutputImpl(console);
this.console.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,59 @@
*/
package org.jboss.forge.addon.shell.aesh;

import org.jboss.aesh.console.helper.ManProvider;

import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

import org.jboss.aesh.console.helper.ManProvider;
import org.jboss.forge.addon.shell.CommandManager;
import org.jboss.forge.addon.shell.ShellImpl;
import org.jboss.forge.addon.shell.ui.ShellContextImpl;
import org.jboss.forge.addon.ui.UICommand;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class ForgeManProvider implements ManProvider {
@Override
public InputStream getManualDocument(String command) {
return null;
}
public class ForgeManProvider implements ManProvider
{
private static final List<String> extensions = Arrays.asList("txt", "ad", "asciidoc");

private final ShellImpl shell;
private final CommandManager manager;

public ForgeManProvider(ShellImpl shell, CommandManager manager)
{
this.shell = shell;
this.manager = manager;
}

@Override
public InputStream getManualDocument(String command)
{
for (UICommand cmd : manager.getAllCommands())
{
ShellContextImpl context = shell.newShellContext();
try
{
if (command.equals(manager.getCommandName(context, cmd)))
{
Class<? extends UICommand> commandType = cmd.getMetadata(context).getType();
InputStream stream = null;
for (String ext : extensions)
{
stream = commandType.getClassLoader().getResourceAsStream(
commandType.getName().replaceAll("\\.", File.separator) + "." + ext);
if (stream != null)
return stream;
}
}
}
finally
{
context.destroy();
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
LESS(1)
===========
:doctype: manpage


NAME
----
*exit* - exit the shell


SYNOPSIS
--------
*exit*


DESCRIPTION
-----------
'Exit' is a program that triggers shell shutdown. `PreShutdown` events and tasks will be processed prior
to actual shell termination.


COMMANDS
--------
none


BUGS
----
never


AUTHOR
------
The Forge Team


RESOURCES
---------
forge: <http://forge.jboss.org/>


COPYING
-------
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
4 changes: 2 additions & 2 deletions shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</modules>

<properties>
<version.aesh>0.43-SNAPSHOT</version.aesh>
<version.aesh.extensions>0.43-SNAPSHOT</version.aesh.extensions>
<version.aesh>0.43</version.aesh>
<version.aesh.extensions>0.43</version.aesh.extensions>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit b242333

Please sign in to comment.