pombreda / clamshell-cli

Automatically exported from code.google.com/p/clamshell-cli
Apache License 2.0
0 stars 0 forks source link

Plugin not running #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I followed the Wiki to create a plugin but it does not work. It gets listed 
when I run the help command but does not run and prints the following:

Command unhandled.
No controller found to respond to [property].

Following is my Plugin Code:

public class PropertyCmd implements Command {

    private static final String NAMESPACE = "syscmd";
    private static final String ACTION_NAME = "property";

    @Override
    public Object execute(Context ctx) {
        IOConsole console = ctx.getIoConsole();
        console.writeOutput(String.format("%n%s%n%n",new Date().toString()));
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.clamshellcli.api.Command#getDescriptor()
     */
    @Override
    public Descriptor getDescriptor() {
        return new Command.Descriptor() {
            @Override
            public String getNamespace() {
                return NAMESPACE;
            }

            @Override
            public String getName() {
                return ACTION_NAME;
            }

            @Override
            public String getDescription() {
                return "Prints MyPortal Properties";
            }

            @Override
            public String getUsage() {
                return "Type 'property'";
            }

            @Override
            public Map<String, String> getArguments() {
                return Collections.emptyMap();
            }
        };
    }

    @Override
    public void plug(Context arg0) {
        // TODO Auto-generated method stub

    }

}

Original issue reported on code.google.com by emtiazah...@gmail.com on 11 Apr 2012 at 8:33

GoogleCodeExporter commented 9 years ago
Ok. I got it, It is mentioned nowhere that I have to add my command in the list 
of commands in cli.config. 

Original comment by emtiazah...@gmail.com on 11 Apr 2012 at 11:39

GoogleCodeExporter commented 9 years ago
Will update the doc.

Original comment by vladimir...@gmail.com on 23 Apr 2012 at 10:38

GoogleCodeExporter commented 9 years ago
I have added a section on updating cli.config.

Original comment by vladimir...@gmail.com on 23 Apr 2012 at 11:03

GoogleCodeExporter commented 9 years ago
Thanks man.

Original comment by emtiazah...@gmail.com on 23 Apr 2012 at 6:52

GoogleCodeExporter commented 9 years ago
I am doing some simple projects.

Same problem for me as well, I have done exactly same as mentioned in the 
webpage but gives me error. Any idea ?

Also how do I get rid of the clamshell banner at the front ?

b64-cli > help

Available Commands
------------------
   base_64       Prints base 64 information
      exit       Exits ClamShell.
      help       Displays help information for available commands.
   sysinfo       Displays current JVM runtime information.

b64-cli > base_64

Command unhandled. 
No controller found to respond to [base_64].

Here is my code and config:

cat cli.config
{
    "properties":{
        "libDir":"./lib",
        "pluginsDir":"./plugins"
    },
    "controllers":{
        "org.clamshellcli.base64.Base64Controller":{
            "enabled":"true",
            "inputPattern":"\\s*(exit|base_64)\\b.*",
            "expectedInputs":[]
        },
        "org.clamshellcli.impl.CmdController":{
            "enabled":"true",
            "inputPattern":"\\s*(exit|help|sysinfo|time)\\b.*",
            "expectedInputs":[]
        }
    }
}

org.clamshellcli.api.Plugin is having:

org.clamshellcli.base64.Base64SplashScreen
org.clamshellcli.base64.Base64Prompt
org.clamshellcli.base64.Base64Controller

package org.clamshellcli.base64;
import java.util.Collections;
import java.util.Date;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.clamshellcli.api.Command;
import org.clamshellcli.api.Context;
import org.clamshellcli.api.IOConsole;

public class Base64Controller implements Command  {

    private static final String NAMESPACE = "base64";
    private static final String ACTION_NAME = "base_64";

    @Override
    public Object execute(Context ctx) {
        IOConsole console = ctx.getIoConsole();
        console.writeOutput(String.format("%n%s%n%n",new Date().toString()));
        byte[] encodedBytes = Base64.encodeBase64("JavaTips.net".getBytes());

        console.writeOutput("encodedBytes " + new String(encodedBytes));
        byte[] decodedBytes = Base64.decodeBase64(encodedBytes);
        console.writeOutput("decodedBytes " + new String(decodedBytes));
        return null;
    }

    @Override
    public Descriptor getDescriptor(){
        return new Command.Descriptor() {
            @Override public String getNamespace() {return NAMESPACE;}

            @Override
            public String getName() {
                return ACTION_NAME;
            }

            @Override
            public String getDescription() {
               return "Prints base 64 information";
            }

            @Override
            public String getUsage() {
                return "Type 'base_64'";
            }

            @Override
            public Map<String, String> getArguments() {
                return Collections.emptyMap();
            }
        };
    }   

    @Override
    public void plug(Context plug) {
        // no load-time setup needed
    }
}

Original comment by kaustabh...@gmail.com on 12 Sep 2012 at 6:43

GoogleCodeExporter commented 9 years ago
Hi. There are couple of things you should change:

1. You are implementing the Command interface (not an InputController).  You 
should rename your command to Base64Command (not Base64Controller).

2.  Since you are creating a Command (not an InputController)  you don't need 
to declare a controller in the config file.  Your config should look like the 
following:

{
    "properties":{
        "libDir":"./lib",
        "pluginsDir":"./plugins"
    },
    "controllers":{
        "org.clamshellcli.impl.CmdController":{
            "enabled":"true",
            "inputPattern":"\\s*(exit|help|sysinfo|time|base_64)\\b.*",
            "expectedInputs":[]
        }
    }
}

Hope this helps.

Original comment by vladimir...@gmail.com on 12 Sep 2012 at 1:22

GoogleCodeExporter commented 9 years ago
@kaustabh: to remove the clamshell banner, just remove the splashscreen jar 
from the plugins directory.  Or see the following to see how to implement your 
own SplashScreen interface - 
http://code.google.com/p/clamshell-cli/source/browse/clamshell-impl-splashscreen
/src/main/java/org/clamshellcli/impl/CliSplashScreen.java

Original comment by vladimir...@gmail.com on 12 Sep 2012 at 7:32

GoogleCodeExporter commented 9 years ago
Many thanks :) The tips were helpful and I figured out the rest. 

Original comment by kaustabh...@gmail.com on 17 Sep 2012 at 4:27