001package com.dpillay.tools.tail4j.launcher;
002
003import java.io.File;
004
005public enum CommandLineOption {
006        INVALID_OPTION(null, 0), SHOW_LINES_OPTION("-n", 1), FORCE_OPTION("-f", 0), HELP_OPTION(
007                        "-h", 0), HELP_DESC_OPTION("--help", 0), FILE_ARGUMENT(null, 0);
008
009        private int skipArgs = 0;
010        private String option = null;
011
012        public String getOption() {
013                return option;
014        }
015
016        public int getSkipArgs() {
017                return skipArgs;
018        }
019
020        CommandLineOption(String option, int skipArgs) {
021                this.option = option;
022                this.skipArgs = skipArgs;
023        }
024
025        public static CommandLineOption getCommandLineOption(String arg) {
026                for (CommandLineOption option : CommandLineOption.values()) {
027                        String optionValue = option.getOption();
028                        if (optionValue != null && optionValue.equals(arg))
029                                return option;
030                }
031                if (!arg.startsWith("-")) {
032                        File file = new File(arg);
033                        if (file.exists()) {
034                                return CommandLineOption.FILE_ARGUMENT;
035                        }
036                }
037                return CommandLineOption.INVALID_OPTION;
038        }
039}