Skip to content

Commit

Permalink
Merge pull request #1116 from sakata1222/DOC/fix-typo
Browse files Browse the repository at this point in the history
[#1116] DOC: improve Guice example in user manual
  • Loading branch information
remkop authored Jun 20, 2020
2 parents 0d2b2ac + 3d19c49 commit 09061f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6145,7 +6145,8 @@ The below example shows how to create a <<Custom Factory,custom `IFactory`>> imp
[source,java]
----
import com.google.inject.*;
import picocli.CommandLine.IFactory;
import picocli.*;
import picocli.CommandLine.*;
public class GuiceFactory implements IFactory {
private final Injector injector = Guice.createInjector(new DemoModule());
Expand All @@ -6155,15 +6156,14 @@ public class GuiceFactory implements IFactory {
try {
return injector.getInstance(aClass);
} catch (ConfigurationException ex) { // no implementation found in Guice configuration
return CommandLine.defaultFactory().create(clazz); // fallback if missing
return CommandLine.defaultFactory().create(aClass); // fallback if missing
}
}
static class DemoModule extends AbstractModule {
@Override
protected void configure() {
bind(java.util.List.class).to(java.util.LinkedList.class);
bind(Runnable.class).to(InjectionDemo.class);
}
}
}
Expand All @@ -6173,7 +6173,9 @@ Use the custom factory when creating a `CommandLine` instance, or when invoking

[source,java]
----
import javax.inject.Inject;
import javax.inject.*;
import picocli.*;
import picocli.CommandLine.*;
@Command(name = "di-demo")
public class InjectionDemo implements Runnable {
Expand All @@ -6182,7 +6184,7 @@ public class InjectionDemo implements Runnable {
@Option(names = "-x") int x;
public static void main(String[] args) {
new CommandLine(Runnable.class, new GuiceFactory()).execute(args);
new CommandLine(InjectionDemo.class, new GuiceFactory()).execute(args);
}
@Override
Expand Down
12 changes: 7 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9122,7 +9122,8 @@ <h3 id="_guice_example">21.1. Guice Example</h3>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">com.google.inject</span>.*;
<span class="keyword">import</span> <span class="include">picocli.CommandLine.IFactory</span>;
<span class="keyword">import</span> <span class="include">picocli</span>.*;
<span class="keyword">import</span> <span class="include">picocli.CommandLine</span>.*;

<span class="directive">public</span> <span class="type">class</span> <span class="class">GuiceFactory</span> <span class="directive">implements</span> IFactory {
<span class="directive">private</span> <span class="directive">final</span> Injector injector = Guice.createInjector(<span class="keyword">new</span> DemoModule());
Expand All @@ -9132,15 +9133,14 @@ <h3 id="_guice_example">21.1. Guice Example</h3>
<span class="keyword">try</span> {
<span class="keyword">return</span> injector.getInstance(aClass);
} <span class="keyword">catch</span> (<span class="exception">ConfigurationException</span> ex) { <span class="comment">// no implementation found in Guice configuration</span>
<span class="keyword">return</span> CommandLine.defaultFactory().create(clazz); <span class="comment">// fallback if missing</span>
<span class="keyword">return</span> CommandLine.defaultFactory().create(aClass); <span class="comment">// fallback if missing</span>
}
}

<span class="directive">static</span> <span class="type">class</span> <span class="class">DemoModule</span> <span class="directive">extends</span> AbstractModule {
<span class="annotation">@Override</span>
<span class="directive">protected</span> <span class="type">void</span> configure() {
bind(java.util.List.class).to(java.util.LinkedList.class);
bind(<span class="predefined-type">Runnable</span>.class).to(InjectionDemo.class);
}
}
}</code></pre>
Expand All @@ -9151,7 +9151,9 @@ <h3 id="_guice_example">21.1. Guice Example</h3>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">javax.inject.Inject</span>;
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">javax.inject</span>.*;
<span class="keyword">import</span> <span class="include">picocli</span>.*;
<span class="keyword">import</span> <span class="include">picocli.CommandLine</span>.*;

<span class="annotation">@Command</span>(name = <span class="string"><span class="delimiter">&quot;</span><span class="content">di-demo</span><span class="delimiter">&quot;</span></span>)
<span class="directive">public</span> <span class="type">class</span> <span class="class">InjectionDemo</span> <span class="directive">implements</span> <span class="predefined-type">Runnable</span> {
Expand All @@ -9160,7 +9162,7 @@ <h3 id="_guice_example">21.1. Guice Example</h3>
<span class="annotation">@Option</span>(names = <span class="string"><span class="delimiter">&quot;</span><span class="content">-x</span><span class="delimiter">&quot;</span></span>) <span class="type">int</span> x;

<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> main(<span class="predefined-type">String</span><span class="type">[]</span> args) {
<span class="keyword">new</span> CommandLine(<span class="predefined-type">Runnable</span>.class, <span class="keyword">new</span> GuiceFactory()).execute(args);
<span class="keyword">new</span> CommandLine(InjectionDemo.class, <span class="keyword">new</span> GuiceFactory()).execute(args);
}

<span class="annotation">@Override</span>
Expand Down

0 comments on commit 09061f0

Please sign in to comment.