/*
 * Copyright 2014 gitblit.com.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitblit.plugins.cookbook;

import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;

import ro.fortsoft.pf4j.Extension;
import ro.fortsoft.pf4j.Plugin;
import ro.fortsoft.pf4j.PluginWrapper;

import com.gitblit.transport.ssh.CommandMetaData;
import com.gitblit.transport.ssh.commands.SshCommand;

public class GitblitCookbookPlugin extends Plugin {

  public GitblitCookbookPlugin(PluginWrapper wrapper) {
    super(wrapper);
  }

  @Override
  public void start() {
    // no op
  }

  @Override
  public void stop() {
    // no op
  }

  @Extension
  @CommandMetaData(name = "hello", description = "Say hello in different languages")
  public static class HelloWorldCommand extends SshCommand {

    @Argument(usage = "name of user")
    private String name = "world";

    @Option(name = "--french", usage = "output in French?")
    private boolean french = false;

    @Override
    public void run() {
      final String greeting = (french ? "Bonjour " : "Hello ");
      stdout.print(greeting + name + "!\n");
    }
  }
}

@@ -806,16 +806,130 @@
 apper;%0A%0A
+import com.gitblit.manager.IGitblit;%0Aimport com.gitblit.models.ServerStatus;%0Aimport com.gitblit.models.UserModel;%0A
 import c
@@ -953,16 +953,25 @@
 ort.ssh.
+commands.
 CommandM
@@ -979,16 +979,75 @@
 taData;%0A
+import com.gitblit.transport.ssh.commands.DispatchCommand;%0A
 import c
@@ -1340,478 +1340,1939 @@
 %0A%0A  
-@Extension%0A  @CommandMetaData(name = %22hello%22, description = %22Say hello in different languages%22)%0A  public static class HelloWorldCommand extends SshCommand %7B%0A%0A    @Argument(usage = %22name of user%22)%0A    private String name = %22world%22;%0A%0A    @Option(name = %22--french%22, usage = %22output in French?%22)%0A    private boolean french = false;%0A%0A    @Override%0A    public void run() %7B%0A      final String greeting = (french ? %22Bonjour %22 : %22Hello %22);%0A      stdout.print(greeting + name + %22!
+/**%0A   * You must register a dispatcher for your custom commands.  The dispatcher%0A   * must be annotated with CommandMetaData.  This annotation will assign the%0A   * plugin command namespace and offer a description.%0A   *%0A   */%0A  @Extension%0A  @CommandMetaData(name = %22cookbook%22, description = %22Example commands%22)%0A  public static class CookbookDispatcher extends DispatchCommand %7B%0A    @Override%0A    protected void registerCommands(UserModel user) %7B%0A        registerCommand(user, HelloWorldCommand.class);%0A        registerCommand(user, StatusCommand.class);%0A    %7D%0A  %7D%0A%0A  /**%0A   * Example HelloWorld command.%0A   */%0A  @CommandMetaData(name = %22hello%22, description = %22Say hello in different languages%22)%0A  public static class HelloWorldCommand extends SshCommand %7B%0A%0A    @Argument(usage = %22name of user%22)%0A    private String name = %22world%22;%0A%0A    @Option(name = %22--french%22, usage = %22output in French?%22)%0A    private boolean french = false;%0A%0A    @Override%0A    public void run() %7B%0A      final String greeting = (french ? %22Bonjour %22 : %22Hello %22);%0A      stdout.print(greeting + name + %22!%5Cn%22);%0A    %7D%0A  %7D%0A%0A  /**%0A   * Example status command.%0A   */%0A  @CommandMetaData(name = %22status%22, description = %22Display the server status%22)%0A  public static class StatusCommand extends SshCommand %7B%0A%0A    @Override%0A    public void run() %7B%0A      IGitblit gitblit = getContext().getGitblit();%0A      ServerStatus status = gitblit.getStatus();%0A      stdout.print(%22version:        %22 + status.version + %22%5Cn%22);%0A      stdout.print(%22releaseDate:    %22 + status.releaseDate + %22%5Cn%22);%0A      stdout.print(%22isGO:           %22 + status.isGO + %22%5Cn%22);%0A      stdout.print(%22container:      %22 + status.servletContainer + %22%5Cn%22);%0A      stdout.print(%22bootDate:       %22 + status.bootDate + %22%5Cn%22);%0A      stdout.print(%22heap maximum:   %22 + status.heapMaximum + %22%5Cn%22);%0A      stdout.print(%22     allocated: %22 + status.heapAllocated + %22%5Cn%22);%0A      stdout.print(%22     free:      %22 + status.heapFree + %22
 %5Cn%22)

Revise plugin example for dispatchers