Improved CLI commands.
This commit is contained in:
parent
2ec1b2e926
commit
a0ba83b885
2 changed files with 69 additions and 68 deletions
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package fr.devinsy.statoolinfos.cli;
|
package fr.devinsy.statoolinfos.cli;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ public final class CLIUtils
|
||||||
public static boolean isMatching(final String[] args, final String... regexps)
|
public static boolean isMatching(final String[] args, final String... regexps)
|
||||||
{
|
{
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
if ((args.length == 0) && (regexps == null))
|
if ((args.length == 0) && (regexps == null))
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -69,9 +70,9 @@ public final class CLIUtils
|
||||||
{
|
{
|
||||||
if (index < args.length)
|
if (index < args.length)
|
||||||
{
|
{
|
||||||
String arg = args[index];
|
String arg = StringUtils.trim(args[index]);
|
||||||
String regexp = regexps[index];
|
String regexp = regexps[index];
|
||||||
|
|
||||||
if (arg.matches(regexp))
|
if (arg.matches(regexp))
|
||||||
{
|
{
|
||||||
index += 1;
|
index += 1;
|
||||||
|
@ -89,7 +90,7 @@ public final class CLIUtils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +129,7 @@ public final class CLIUtils
|
||||||
{
|
{
|
||||||
if (index < args.length)
|
if (index < args.length)
|
||||||
{
|
{
|
||||||
String arg = args[index];
|
String arg = StringUtils.trim(args[index]);
|
||||||
String regexp;
|
String regexp;
|
||||||
if (index < regexps.length)
|
if (index < regexps.length)
|
||||||
{
|
{
|
||||||
|
|
|
@ -116,14 +116,14 @@ public final class StatoolInfosCLI
|
||||||
message.appendln(" statoolinfos tagdate <fileordirectory> update the file.datetime file");
|
message.appendln(" statoolinfos tagdate <fileordirectory> update the file.datetime file");
|
||||||
message.appendln(" statoolinfos uptime <configurationfile> update uptime journal");
|
message.appendln(" statoolinfos uptime <configurationfile> update uptime journal");
|
||||||
message.appendln();
|
message.appendln();
|
||||||
message.appendln(" statoolinfos list files <logfilesorconfigfile> display http access log files");
|
message.appendln(" statoolinfos list file <logfilesorconfigfile> display http access log files");
|
||||||
message.appendln(" statoolinfos list logs [-bot|-nobot] <logfilesorconfigfile> display http access log lines");
|
message.appendln(" statoolinfos list log [-bot|-nobot] <logfilesorconfigfile> display http access log lines");
|
||||||
message.appendln(" statoolinfos list ip [-bot|-nobot] <logfiles> generate ip list from http log file");
|
message.appendln(" statoolinfos list ip [-bot|-nobot] <logfiles> generate ip list from http log file");
|
||||||
message.appendln(" statoolinfos list ua [-bot|-nobot] <logfiles> generate user agent list from http log file");
|
message.appendln(" statoolinfos list ua [-bot|-nobot] <logfiles> generate user agent list from http log file");
|
||||||
message.appendln(" statoolinfos list visitors [-bot|-nobot] <logfiles> generate visitors (ip+ua) list from http log file");
|
message.appendln(" statoolinfos list visitor [-bot|-nobot] <logfiles> generate visitors (ip+ua) list from http log file");
|
||||||
message.appendln(" statoolinfos stat ip [-bot|-nobot] <logfiles> generate stats about ip from http log file");
|
message.appendln(" statoolinfos stat ip [-bot|-nobot] <logfiles> generate stats about ip from http log file");
|
||||||
message.appendln(" statoolinfos stat ua [-bot|-nobot] <logfiles> generate stats about user agent from http log file");
|
message.appendln(" statoolinfos stat ua [-bot|-nobot] <logfiles> generate stats about user agent from http log file");
|
||||||
message.appendln(" statoolinfos stat visitors [-bot|-nobot] <logfiles> generate stats about visitors (ip+ua) from http log file");
|
message.appendln(" statoolinfos stat visitor [-bot|-nobot] <logfiles> generate stats about visitor (ip+ua) from http log file");
|
||||||
|
|
||||||
System.out.print(message.toString());
|
System.out.print(message.toString());
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ public final class StatoolInfosCLI
|
||||||
{
|
{
|
||||||
displayVersion();
|
displayVersion();
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "build", "\\s*.+\\.conf\\s*"))
|
else if (CLIUtils.isMatching(args, "build", ".+\\.conf"))
|
||||||
{
|
{
|
||||||
File configurationFile = new File(StringUtils.trim(args[1]));
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
||||||
try
|
try
|
||||||
|
@ -254,7 +254,7 @@ public final class StatoolInfosCLI
|
||||||
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "clear", "\\s*.+\\.conf\\s*"))
|
else if (CLIUtils.isMatching(args, "clear", ".+\\.conf*"))
|
||||||
{
|
{
|
||||||
File configurationFile = new File(StringUtils.trim(args[1]));
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
||||||
try
|
try
|
||||||
|
@ -266,7 +266,7 @@ public final class StatoolInfosCLI
|
||||||
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "crawl", "\\s*.+\\.conf\\s*"))
|
else if (CLIUtils.isMatching(args, "crawl", ".+\\.conf"))
|
||||||
{
|
{
|
||||||
Chrono chrono = new Chrono().start();
|
Chrono chrono = new Chrono().start();
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ public final class StatoolInfosCLI
|
||||||
}
|
}
|
||||||
System.out.println(chrono.format());
|
System.out.println(chrono.format());
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "format", "\\s*.+\\s*"))
|
else if (CLIUtils.isMatching(args, "format", ".+"))
|
||||||
{
|
{
|
||||||
Files inputs = FilesUtils.searchEndingWith(new File(args[1]), ".properties");
|
Files inputs = FilesUtils.searchEndingWith(new File(args[1]), ".properties");
|
||||||
for (File input : inputs)
|
for (File input : inputs)
|
||||||
|
@ -298,7 +298,7 @@ public final class StatoolInfosCLI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "htmlize", "\\s*.+\\.conf\\s*"))
|
else if (CLIUtils.isMatching(args, "htmlize", ".+\\.conf"))
|
||||||
{
|
{
|
||||||
Chrono chrono = new Chrono().start();
|
Chrono chrono = new Chrono().start();
|
||||||
File configurationFile = new File(StringUtils.trim(args[1]));
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
||||||
|
@ -313,17 +313,7 @@ public final class StatoolInfosCLI
|
||||||
}
|
}
|
||||||
System.out.println(chrono.format());
|
System.out.println(chrono.format());
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "list", "ip", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "ip", "(-all|-bot|-nobot)", ".+"))
|
||||||
{
|
|
||||||
Files files = new Files();
|
|
||||||
for (int source = 2; source < args.length; source++)
|
|
||||||
{
|
|
||||||
files.add(new File(args[source]));
|
|
||||||
}
|
|
||||||
|
|
||||||
StatoolInfos.listIps(files, BotFilter.ALL);
|
|
||||||
}
|
|
||||||
else if (CLIUtils.isMatching(args, "list", "ip", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
|
@ -334,13 +324,23 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.listIps(source, filter);
|
StatoolInfos.listIps(source, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "list", "files", "\\s*.+\\.conf\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "ip", ".+"))
|
||||||
|
{
|
||||||
|
Files files = new Files();
|
||||||
|
for (int source = 2; source < args.length; source++)
|
||||||
|
{
|
||||||
|
files.add(new File(args[source]));
|
||||||
|
}
|
||||||
|
|
||||||
|
StatoolInfos.listIps(files, BotFilter.ALL);
|
||||||
|
}
|
||||||
|
else if (CLIUtils.isMatching(args, "list", "(file|files)", ".+\\.conf"))
|
||||||
{
|
{
|
||||||
File configurationFile = new File(StringUtils.trim(args[2]));
|
File configurationFile = new File(StringUtils.trim(args[2]));
|
||||||
|
|
||||||
StatoolInfos.listFiles(configurationFile);
|
StatoolInfos.listFiles(configurationFile);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "list", "files", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "(file|files)", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
for (int index = 2; index < args.length; index++)
|
for (int index = 2; index < args.length; index++)
|
||||||
|
@ -350,30 +350,20 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.listFiles(source);
|
StatoolInfos.listFiles(source);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "list", "logs", "\\s*.+\\.conf\\s*"))
|
else if (CLIUtils.isMatching(args, "list", "(log|logs)", "(-all|-bot|-nobot)", ".+\\.conf*"))
|
||||||
{
|
|
||||||
File configurationFile = new File(StringUtils.trim(args[2]));
|
|
||||||
|
|
||||||
StatoolInfos.listLogs(configurationFile, BotFilter.ALL);
|
|
||||||
}
|
|
||||||
else if (CLIUtils.isMatching(args, "list", "logs", "(-all|-bot|-nobot)", "\\s*.+\\.conf\\s*"))
|
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
File configurationFile = new File(StringUtils.trim(args[3]));
|
File configurationFile = new File(StringUtils.trim(args[3]));
|
||||||
|
|
||||||
StatoolInfos.listLogs(configurationFile, filter);
|
StatoolInfos.listLogs(configurationFile, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "list", "logs", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatching(args, "list", "(log|logs)", ".+\\.conf"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
File configurationFile = new File(StringUtils.trim(args[2]));
|
||||||
for (int index = 2; index < args.length; index++)
|
|
||||||
{
|
|
||||||
source.add(new File(args[index]));
|
|
||||||
}
|
|
||||||
|
|
||||||
StatoolInfos.listLogs(source, BotFilter.ALL);
|
StatoolInfos.listLogs(configurationFile, BotFilter.ALL);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "list", "logs", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "(log|logs)", "(-all|-bot|-nobot)", ".+"))
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
|
@ -384,7 +374,7 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.listLogs(source, filter);
|
StatoolInfos.listLogs(source, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "list", "(useragent|ua)", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "(log|logs)", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
for (int index = 2; index < args.length; index++)
|
for (int index = 2; index < args.length; index++)
|
||||||
|
@ -392,9 +382,9 @@ public final class StatoolInfosCLI
|
||||||
source.add(new File(args[index]));
|
source.add(new File(args[index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
StatoolInfos.listUserAgents(source, BotFilter.ALL);
|
StatoolInfos.listLogs(source, BotFilter.ALL);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "list", "(useragent|ua)", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "(useragent|ua)", "(-all|-bot|-nobot)", ".+"))
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
|
@ -405,7 +395,7 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.listUserAgents(source, filter);
|
StatoolInfos.listUserAgents(source, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "list", "visitors", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "(useragent|ua)", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
for (int index = 2; index < args.length; index++)
|
for (int index = 2; index < args.length; index++)
|
||||||
|
@ -413,9 +403,9 @@ public final class StatoolInfosCLI
|
||||||
source.add(new File(args[index]));
|
source.add(new File(args[index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
StatoolInfos.listVisitors(source, BotFilter.ALL);
|
StatoolInfos.listUserAgents(source, BotFilter.ALL);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "list", "visitors", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "(visitor|visitors)", "(-all|-bot|-nobot)", ".+"))
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
|
@ -426,7 +416,17 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.listVisitors(source, filter);
|
StatoolInfos.listVisitors(source, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "probe", "\\S*(-full|-today|-previousday|-\\d+)\\s*", "\\s*.+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "list", "(visitor|visitors)", ".+"))
|
||||||
|
{
|
||||||
|
Files source = new Files();
|
||||||
|
for (int index = 2; index < args.length; index++)
|
||||||
|
{
|
||||||
|
source.add(new File(args[index]));
|
||||||
|
}
|
||||||
|
|
||||||
|
StatoolInfos.listVisitors(source, BotFilter.ALL);
|
||||||
|
}
|
||||||
|
else if (CLIUtils.isMatching(args, "probe", "(-full|-today|-previousday|-\\d+)", ".+"))
|
||||||
{
|
{
|
||||||
File configurationFile = new File(StringUtils.trim(args[2]));
|
File configurationFile = new File(StringUtils.trim(args[2]));
|
||||||
|
|
||||||
|
@ -479,17 +479,7 @@ public final class StatoolInfosCLI
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "stat", "ip", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "stat", "ip", "(-all|-bot|-nobot)", ".+"))
|
||||||
{
|
|
||||||
Files source = new Files();
|
|
||||||
for (int index = 2; index < args.length; index++)
|
|
||||||
{
|
|
||||||
source.add(new File(args[index]));
|
|
||||||
}
|
|
||||||
|
|
||||||
StatoolInfos.statIps(source, BotFilter.ALL);
|
|
||||||
}
|
|
||||||
else if (CLIUtils.isMatching(args, "stat", "ip", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
|
@ -500,7 +490,7 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.statIps(source, filter);
|
StatoolInfos.statIps(source, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "stat", "(useragent|ua)", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "stat", "ip", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
for (int index = 2; index < args.length; index++)
|
for (int index = 2; index < args.length; index++)
|
||||||
|
@ -508,9 +498,9 @@ public final class StatoolInfosCLI
|
||||||
source.add(new File(args[index]));
|
source.add(new File(args[index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
StatoolInfos.statUserAgents(source, BotFilter.ALL);
|
StatoolInfos.statIps(source, BotFilter.ALL);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "stat", "(useragent|ua)", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "stat", "(useragent|ua)", "(-all|-bot|-nobot)", ".+"))
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
|
@ -521,7 +511,7 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.statUserAgents(source, filter);
|
StatoolInfos.statUserAgents(source, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "stat", "visitors", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "stat", "(useragent|ua)", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
for (int index = 2; index < args.length; index++)
|
for (int index = 2; index < args.length; index++)
|
||||||
|
@ -529,9 +519,9 @@ public final class StatoolInfosCLI
|
||||||
source.add(new File(args[index]));
|
source.add(new File(args[index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
StatoolInfos.statVisitors(source, BotFilter.ALL);
|
StatoolInfos.statUserAgents(source, BotFilter.ALL);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "stat", "visitors", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "stat", "(visitor|visitors)", "(-all|-bot|-nobot)", ".+"))
|
||||||
{
|
{
|
||||||
BotFilter filter = parseLogFilterOption(args[2]);
|
BotFilter filter = parseLogFilterOption(args[2]);
|
||||||
Files source = new Files();
|
Files source = new Files();
|
||||||
|
@ -542,7 +532,17 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.statVisitors(source, filter);
|
StatoolInfos.statVisitors(source, filter);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "tagdate", "\\s*.+\\s*"))
|
else if (CLIUtils.isMatchingEllipsis(args, "stat", "(visitor|visitors)", ".+"))
|
||||||
|
{
|
||||||
|
Files source = new Files();
|
||||||
|
for (int index = 2; index < args.length; index++)
|
||||||
|
{
|
||||||
|
source.add(new File(args[index]));
|
||||||
|
}
|
||||||
|
|
||||||
|
StatoolInfos.statVisitors(source, BotFilter.ALL);
|
||||||
|
}
|
||||||
|
else if (CLIUtils.isMatching(args, "tagdate", ".+"))
|
||||||
{
|
{
|
||||||
Files inputs = FilesUtils.searchEndingWith(new File(args[1]), ".properties");
|
Files inputs = FilesUtils.searchEndingWith(new File(args[1]), ".properties");
|
||||||
for (File input : inputs)
|
for (File input : inputs)
|
||||||
|
@ -558,7 +558,7 @@ public final class StatoolInfosCLI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "uptime", "\\s*.+\\.conf\\s*"))
|
else if (CLIUtils.isMatching(args, "uptime", ".+\\.conf"))
|
||||||
{
|
{
|
||||||
Chrono chrono = new Chrono().start();
|
Chrono chrono = new Chrono().start();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue