Advertisement
NLinker

JCommander example

Sep 19th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1.     @Parameters(
  2.         commandNames = "sound-cloud-filter",
  3.         commandDescription = "Copy resolver data",
  4.         separators = "=")
  5.     public static class CmdOpts {
  6.         @Parameter(
  7.             names = {"-e", "--env"},
  8.             required = true,
  9.             description = "Environment to analyze data on",
  10.             converter = EnvConverter.class)
  11.         private Env env;
  12.  
  13.         @Parameter(
  14.             // names = the rest of the parameters passed
  15.             required = true,
  16.             description = "Execution modes list")
  17.         private List<Mode> modes;
  18.  
  19.         // needed for JCommander
  20.         public CmdOpts() {
  21.         }
  22.  
  23.         public CmdOpts(Env env, List<Mode> modes) {
  24.             this.env = env;
  25.             this.modes = modes;
  26.         }
  27.  
  28.         @Override
  29.         public String toString() {
  30.             //noinspection StringBufferReplaceableByString
  31.             final StringBuilder sb = new StringBuilder("CmdOpts(");
  32.             sb.append("env=").append(env);
  33.             sb.append(", modes=").append(modes);
  34.             sb.append(')');
  35.             return sb.toString();
  36.         }
  37.  
  38.         @Override
  39.         public void execute() {
  40.             // interface Cmd is enforced here by CommandLauncher
  41.             new SoundCloudFilter(this).run();
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement