View Javadoc
1   /**************************************************************************
2    *
3    * Copyright (c) 2017-2019 Yawg project contributors.
4    *
5    **************************************************************************/
6   
7   package com.varmateo.yawg.cli;
8   
9   import java.io.OutputStream;
10  
11  import io.vavr.collection.List;
12  import io.vavr.collection.Seq;
13  
14  
15  /**
16   * Set of parameters required to create a {@code BakerCli} instance.
17   */
18  public final class BakerCliRunOptions {
19  
20  
21      private static final String DEFAULT_ARGV0 = "yawg";
22  
23  
24      public final String argv0;
25      public final String[] args;
26      public final OutputStream output;
27  
28  
29      /**
30       *
31       */
32      private BakerCliRunOptions(final Builder builder) {
33  
34          argv0 = builder._argv0;
35          args = builder._args.toJavaArray(String.class);
36          output = builder._output;
37      }
38  
39  
40      /**
41       * Creates a newly initialized builder for creating a
42       * <code>BakerCliRunOptions</code> instance.
43       *
44       * @return A new builder.
45       */
46      public static Builder builder() {
47  
48          return new Builder();
49      }
50  
51  
52      /**
53       *
54       */
55      public static final class Builder {
56  
57  
58          private String _argv0;
59          private Seq<String> _args;
60          private OutputStream _output;
61  
62  
63          /**
64           *
65           */
66          private Builder() {
67  
68              _argv0 = DEFAULT_ARGV0;
69              _args = List.of();
70              _output = System.out;
71          }
72  
73  
74          /**
75           * @param argv0 The name the utility was launched with on the
76           * command line. It will be used in informative or error
77           * messages.
78           */
79          public Builder argv0(final String argv0) {
80  
81              _argv0 = argv0;
82  
83              return this;
84          }
85  
86  
87          /**
88           * @param args The command line arguments passed to the
89           * utility.
90           */
91          public Builder addArgs(final String... args) {
92  
93              _args = _args.appendAll(List.of(args));
94  
95              return this;
96          }
97  
98  
99          /**
100          *
101          */
102         public Builder output(final OutputStream output) {
103 
104             _output = output;
105 
106             return this;
107         }
108 
109 
110         /**
111          *
112          */
113         public BakerCliRunOptions build() {
114 
115             return new BakerCliRunOptions(this);
116         }
117 
118 
119     }
120 
121 
122 }