keith-turner commented on a change in pull request #1083: [WIP] POC for Command
module with centralized Command Pattern logic
URL: https://github.com/apache/fluo/pull/1083#discussion_r357778156
##########
File path: modules/command/src/main/java/org/apache/fluo/command/FluoExec.java
##########
@@ -44,25 +50,39 @@ protected void configure() {
}
}
- public static void main(String[] args) throws Exception {
- if (args.length < 2) {
- System.err.println("Usage: fluo exec <app> <class> args...");
- System.exit(-1);
+ @Parameter(description = "<app> <class> args...", variableArity = true)
+ private List<String> args;
+
+ @Override
+ public void execute() throws FluoCommandException {
+ if (args.size() < 2) {
+ throw new FluoCommandException("Usage: fluo exec <app> <class> args...");
}
- final String applicationName = args[0];
- final String className = args[1];
+ final String applicationName = args.get(0);
+ final String className = args.get(1);
FluoConfiguration fluoConfig = CommandUtil.resolveFluoConfig();
fluoConfig.setApplicationName(applicationName);
CommandUtil.verifyAppInitialized(fluoConfig);
fluoConfig = FluoAdminImpl.mergeZookeeperConfig(fluoConfig);
- Class<?> clazz = Class.forName(className);
+ try {
+ Class<?> clazz = Class.forName(className);
+
+ // inject fluo configuration
+ Guice.createInjector(new FluoConfigModule(clazz, fluoConfig));
- // inject fluo configuration
- Guice.createInjector(new FluoConfigModule(clazz, fluoConfig));
+ Method method = clazz.getMethod("main", String[].class);
+ method.invoke(null, args.subList(2, args.size()));
+ } catch (NoSuchMethodException | IllegalAccessException |
InvocationTargetException e) {
+ throw new FluoCommandException(String.format("Class %s must have a main
method", className),
Review comment:
Nice error messages.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services