View Javadoc
1   /**
2    * Copyright 1&1 Internet AG, https://github.com/1and1/
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  package net.oneandone.sushi;
17  
18  import net.oneandone.sushi.cli.Cli;
19  import net.oneandone.sushi.cli.Command;
20  import net.oneandone.sushi.cli.Option;
21  import net.oneandone.sushi.cli.Remaining;
22  import net.oneandone.sushi.cli.Value;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  public class CliSample extends Cli implements Command {
28      public static void main(String[] args) {
29          System.exit(new CliSample().run(args));
30      }
31  
32      @Option("flag")
33      private boolean flag = false;
34      
35      @Option("number")
36      private int number = 7;
37      
38      @Value(name = "first", position = 1)
39      private String first = null;
40  
41      private List<String> remaining = new ArrayList<String>();
42      
43      @Remaining
44      public void addRemaining(String str) {
45          remaining.add(str);
46      }
47      
48      public void invoke() {
49          console.info.println("command invoked with ");
50          console.info.println("   flag = " + flag);
51          console.info.println("   number = " + number);
52          console.info.println("   first = " + first);
53          console.info.println("   remaining = " + remaining);
54      }
55      
56      @Override
57      public void printHelp() {
58          console.info.println("usage: [-flag | -number n] first remaining*");
59      }
60  }