Skip to content

Commit

Permalink
#318 Drop (unnecessary) Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Oct 6, 2024
1 parent dd0bab0 commit 49b6f02
Showing 1 changed file with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ class Main implements Runnable {

MainRunner runner

Main() {
Main(new MainRunner())
}

Main(MainRunner runner) {
protected Main(MainRunner runner) {
this.runner = runner
}

Expand All @@ -49,11 +45,11 @@ class Main implements Runnable {
File[] srcDocs

static void main(String[] args) {
MainRunner runner = new MainRunner()
Main app = new Main(runner)
CommandLine cmd = new CommandLine(app)
runner.setMain(app)
runner.setCmd(cmd)
MainRunner mainRunner = new MainRunner()
Main main = new Main(mainRunner)
CommandLine cmd = new CommandLine(main)
mainRunner.setMain(main)
mainRunner.setCmd(cmd)
cmd.execute(args)
}

Expand All @@ -66,16 +62,7 @@ class Main implements Runnable {
.collect { it.toFile() }
}

static class MainRunner implements CommandLine.IFactory {

@Override
<T> T create(Class<T> cls) throws Exception {
if (cls == Main.class) {
return (T) new Main()
} else {
throw new IllegalArgumentException("Cannot create CLI applications of class '${cls}'")
}
}
static class MainRunner {

Main main
CommandLine cmd
Expand Down

0 comments on commit 49b6f02

Please sign in to comment.