added groups for subcommands

This commit is contained in:
Sebastian Sdorra
2011-05-22 14:36:32 +02:00
parent 029aed3e82
commit 01e5e02c64
26 changed files with 87 additions and 35 deletions

View File

@@ -152,15 +152,7 @@ public class App
if ((args.length == 0) || (subcommand == null) || help) if ((args.length == 0) || (subcommand == null) || help)
{ {
parser.printUsage(output, i18n.getBundle()); printHelp(parser, i18n);
output.println();
output.println(i18n.getMessage(I18n.SUBCOMMANDS_TITLE));
for (CommandDescriptor desc :
SubCommandHandler.getInstance().getDescriptors())
{
output.append(" ").println(desc.getName());
}
} }
else else
{ {
@@ -199,6 +191,37 @@ public class App
} }
} }
/**
* Method description
*
*
* @param parser
* @param i18n
*/
private void printHelp(CmdLineParser parser, I18n i18n)
{
parser.printUsage(output, i18n.getBundle());
output.println();
output.println(i18n.getMessage(I18n.SUBCOMMANDS_TITLE));
output.println();
String group = null;
for (CommandDescriptor desc :
SubCommandHandler.getInstance().getDescriptors())
{
if ((group == null) ||!group.equals(desc.getGroup()))
{
output.println();
group = desc.getGroup();
output.append(i18n.getMessage(group)).println(":");
output.println();
}
output.append(" ").println(desc.getName());
}
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */

View File

@@ -45,7 +45,7 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("add-members") @Command(name = "add-members", group = "group")
public class AddMembersSubCommand extends MembersSubCommand public class AddMembersSubCommand extends MembersSubCommand
{ {

View File

@@ -48,7 +48,7 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("add-permission") @Command(name="add-permission", group="repository")
public class AddPermissionSubCommand extends PermissionSubCommand public class AddPermissionSubCommand extends PermissionSubCommand
{ {

View File

@@ -47,6 +47,7 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface Command public @interface Command
{ {
String value() default ""; String name() default "";
String usage() default ""; String usage() default "";
String group() default "misc";
} }

View File

@@ -69,7 +69,8 @@ public class CommandDescriptor implements Comparable<CommandDescriptor>
if (cmd != null) if (cmd != null)
{ {
this.name = cmd.value(); this.name = cmd.name();
this.group = cmd.group();
this.usage = cmd.usage(); this.usage = cmd.usage();
} }
@@ -108,7 +109,14 @@ public class CommandDescriptor implements Comparable<CommandDescriptor>
@Override @Override
public int compareTo(CommandDescriptor desc) public int compareTo(CommandDescriptor desc)
{ {
return name.compareTo(desc.name); int result = group.compareTo(desc.group);
if (result == 0)
{
result = name.compareTo(desc.name);
}
return result;
} }
/** /**
@@ -147,6 +155,17 @@ public class CommandDescriptor implements Comparable<CommandDescriptor>
return commandClass; return commandClass;
} }
/**
* Method description
*
*
* @return
*/
public String getGroup()
{
return group;
}
/** /**
* Method description * Method description
* *
@@ -174,6 +193,9 @@ public class CommandDescriptor implements Comparable<CommandDescriptor>
/** Field description */ /** Field description */
private Class<? extends SubCommand> commandClass; private Class<? extends SubCommand> commandClass;
/** Field description */
private String group = "misc";
/** Field description */ /** Field description */
private String name; private String name;

View File

@@ -50,7 +50,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("create-group") @Command(name="create-group", group="group")
public class CreateGroupSubCommand extends TemplateSubCommand public class CreateGroupSubCommand extends TemplateSubCommand
{ {

View File

@@ -49,7 +49,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("create-repository") @Command(name="create-repository",group="repository")
public class CreateRepositorySubCommand extends TemplateSubCommand public class CreateRepositorySubCommand extends TemplateSubCommand
{ {

View File

@@ -49,7 +49,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("create-user") @Command(name="create-user", group="user")
public class CreateUserSubCommand extends TemplateSubCommand public class CreateUserSubCommand extends TemplateSubCommand
{ {

View File

@@ -41,7 +41,7 @@ import sonia.scm.cli.config.ScmClientConfig;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("delete-config") @Command(name="delete-config", group="config")
public class DeleteConfigSubCommand extends SubCommand public class DeleteConfigSubCommand extends SubCommand
{ {

View File

@@ -43,7 +43,7 @@ import sonia.scm.client.ScmClientSession;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("delete-group") @Command(name="delete-group",group="group")
public class DeleteGroupSubCommand extends SubCommand public class DeleteGroupSubCommand extends SubCommand
{ {

View File

@@ -45,7 +45,7 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("delete-members") @Command(name="delete-members",group="group")
public class DeleteMembersSubCommand extends MembersSubCommand public class DeleteMembersSubCommand extends MembersSubCommand
{ {

View File

@@ -48,7 +48,7 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("delete-permission") @Command(name="delete-permission",group="repository")
public class DeletePermissionSubCommand extends PermissionSubCommand public class DeletePermissionSubCommand extends PermissionSubCommand
{ {

View File

@@ -43,7 +43,7 @@ import sonia.scm.client.ScmClientSession;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("delete-repository") @Command(name="delete-repository",group="repository")
public class DeleteRepositorySubCommand extends SubCommand public class DeleteRepositorySubCommand extends SubCommand
{ {

View File

@@ -43,7 +43,7 @@ import sonia.scm.client.ScmClientSession;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("delete-user") @Command(name="delete-user",group="user")
public class DeleteUserSubCommand extends SubCommand public class DeleteUserSubCommand extends SubCommand
{ {

View File

@@ -50,7 +50,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("get-group") @Command(name="get-group",group="group")
public class GetGroupSubCommand extends TemplateSubCommand public class GetGroupSubCommand extends TemplateSubCommand
{ {

View File

@@ -50,7 +50,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("get-repository") @Command(name="get-repository",group="repository")
public class GetRepositorySubCommand extends TemplateSubCommand public class GetRepositorySubCommand extends TemplateSubCommand
{ {

View File

@@ -50,7 +50,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("get-user") @Command(name="get-user",group="user")
public class GetUserSubCommand extends TemplateSubCommand public class GetUserSubCommand extends TemplateSubCommand
{ {

View File

@@ -48,7 +48,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("list-groups") @Command(name="list-groups",group="group")
public class ListGroupsSubCommand extends TemplateSubCommand public class ListGroupsSubCommand extends TemplateSubCommand
{ {

View File

@@ -48,7 +48,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("list-repositories") @Command(name="list-repositories",group="repository")
public class ListRepositoriesSubCommand extends TemplateSubCommand public class ListRepositoriesSubCommand extends TemplateSubCommand
{ {

View File

@@ -48,7 +48,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("list-users") @Command(name="list-users",group="user")
public class ListUsersSubCommand extends TemplateSubCommand public class ListUsersSubCommand extends TemplateSubCommand
{ {

View File

@@ -53,7 +53,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("modify-group") @Command(name="modify-group",group="group")
public class ModifyGroupSubCommand extends TemplateSubCommand public class ModifyGroupSubCommand extends TemplateSubCommand
{ {

View File

@@ -53,7 +53,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("modify-repository") @Command(name="modify-repository",group="repository")
public class ModifyRepositorySubCommand extends TemplateSubCommand public class ModifyRepositorySubCommand extends TemplateSubCommand
{ {

View File

@@ -53,7 +53,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("modify-user") @Command(name="modify-user",group="user")
public class ModifyUserSubCommand extends TemplateSubCommand public class ModifyUserSubCommand extends TemplateSubCommand
{ {

View File

@@ -41,7 +41,7 @@ import sonia.scm.cli.config.ScmClientConfig;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Command("store-config") @Command(name = "store-config", group = "config")
public class StoreConfigSubCommand extends SubCommand public class StoreConfigSubCommand extends SubCommand
{ {

View File

@@ -18,7 +18,7 @@
</encoder> </encoder>
</appender> </appender>
<logger name="sonia.scm.cli" level="TRACE" /> <logger name="sonia.scm.cli" level="ERROR" />
<root level="ERROR"> <root level="ERROR">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />

View File

@@ -31,7 +31,7 @@ VAL = value
FILE = file FILE = file
error = Error error = Error
subCommandsTitle = SubCommands subCommandsTitle = list of commands
optionConfig = Configuration name optionConfig = Configuration name
optionServerUrl = SCM-Manager URL optionServerUrl = SCM-Manager URL
@@ -70,3 +70,9 @@ groupNotFoun = The group could not be found
metaVar_config = configname metaVar_config = configname
metaVar_arg = subcommand arguments metaVar_arg = subcommand arguments
metaVar_command = subcommand metaVar_command = subcommand
config = Configuration
misc = Miscellaneous
repository = Repository
group = Group
user = User