1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.dialer.commandline;
18
19import com.android.dialer.commandline.impl.Blocking;
20import com.android.dialer.commandline.impl.Echo;
21import com.android.dialer.commandline.impl.Help;
22import com.android.dialer.commandline.impl.Version;
23import com.android.dialer.function.Supplier;
24import com.google.common.collect.ImmutableMap;
25import dagger.Module;
26import dagger.Provides;
27import javax.inject.Inject;
28
29/** Provides {@link Command} */
30@Module
31public abstract class CommandLineModule {
32
33  @Provides
34  static Supplier<ImmutableMap<String, Command>> provideCommandSupplier(
35      AospCommandInjector aospCommandInjector) {
36
37    return aospCommandInjector.inject(CommandSupplier.builder()).build();
38  }
39
40  /** Injects standard commands to the builder */
41  public static class AospCommandInjector {
42    private final Help help;
43    private final Version version;
44    private final Echo echo;
45    private final Blocking blocking;
46
47    @Inject
48    AospCommandInjector(Help help, Version version, Echo echo, Blocking blocking) {
49      this.help = help;
50      this.version = version;
51      this.echo = echo;
52      this.blocking = blocking;
53    }
54
55    public CommandSupplier.Builder inject(CommandSupplier.Builder builder) {
56      builder.addCommand("help", help);
57      builder.addCommand("version", version);
58      builder.addCommand("echo", echo);
59      builder.addCommand("blocking", blocking);
60      return builder;
61    }
62  }
63}
64